Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Руководство_по_C++_CLI.doc
Скачиваний:
4
Добавлен:
01.07.2025
Размер:
8 Мб
Скачать
☆

2.5Keywords

A name can consist of one word such as country. A name could also be a combination of more than one word, such as firstname or dateofbirth.

The C++ and the C++/CLI languages have a list of words reserved for its own use and you must not use any of these words to name your objects or functions. The reserved words are:

C and C++ Reserved Words

abstract auto bool break case

catch char class const const_cast

continue default delegate delete do

double dynamic_cast each else enum

explicit extern event false finally

float for friend gcnew generic

goto if in inline int

Internal initonly interface literal long

mutable namespace new (pointer) new (abstract) nullptr

operator override private property protected

public ref register reinterpret_cast return

sealed signed sizeof short static

static_cast struct switch template this

true try typedef typeid throw

typename union unsigned using(namespace) using(inheritance)

Value virtual void volatile wchar_t

while where      

Avoid starting the name of a variable with two underscores; sometimes, the compiler would think that you are trying to use one of the words reserved for the compiler.

C++ is case-sensitive; this means that CASE, Case, case, and Case are four completely different words. To make your programming experience easier and personal, you can add your own rules to those above. Some (most) companies also adopt a naming convention throughout their documentation.

Throughout this book, a name will:

  • Start in uppercase, whether it is a variable, a function, a structure, or a class. In some situations, a name will start with an underscore, when useful. Examples are Country, Printer, _Number

  • Start each element of its combined names in uppercase. Examples are FirstName, DateOfBirth

 

   

 

3.Data Types

3.1Variable Initialization

When you declare a variable, as mentioned already, the compiler reserves a space in memory for that variable in the stack. In most languages, that space is left empty until you put a value in it. Initialization is a technique of putting a value into the space memory of a variable. We also state that variable is assigned a value.

To control the behavior of your program, you can assign the desired value to a variable when you declare it. That is, you can initialize a variable when declaring it. There are two main techniques used to initialize a variable.

You can use the equal symbol (also called the assignment operator) to initialize a variable. To do that, after typing the name of the variable, type = followed by the desired value. The formula used would be:

TypeOfVariable VariableName = InitialValue;

Another technique of initializing a variable is by using parentheses. The syntax is:

TypeOfVariable VariableName(InitialValue);

3.2Introduction to Data Types

We have mentioned that the syntax of declaring a variable was:

TypeOfVariable VariableName;

The TypeOfVariable factor lets the compiler know the amount of memory that will be needed for the variable. This TypeOfVariable is commonly called the data type. As we will find out, there are various data types available in C++.

If many different variables are using the same data type, you can declare them on the same line, separating two with a comma, except the last one that would end with a semi-colon. The formula to follow is:

DataType Variable1, Variable2, Variable3;