2.2 Defining variables
2.2.1 Naming rules
The name given to a variable is called an identifier, or it is more easily referred to as a variable name. Variable names are available in letters (including case), numbers, and underscores, and other characters are not allowed. The underscore or letter begins. The visual c++2010 characters can be up to 2048 characters long. A common convention in C + + is to use a name that starts with a capital letter for the class name, and a name that starts with a lowercase letter for the variable.
Keywords in C + +
There are some reserved words in C + +, also known as keywords; modify the display color: tools->options->environment/fonts and colors.
2.2.2 Declaring variables
A variable declaration is also a variable definition, which describes the variable name and links it to a memory of the appropriate capacity.
When introducing a name and information about the use of the name to the program, the term "declaration" is used to refer to the computer memory assigned to the name. As far as variables are concerned, they are executed simultaneously. C + + Good habit is to declare them near the position of the first used variable.
2.2.3 The initial value of the variable
A variable declaration that assigns an initial value to a variable is called initialization.
In C + +, there is also a notation for writing the initial value of a variable, called function notation. is to write the value in parentheses after the variable name.
Eg:int value (5); int value = 5.
2.3 Basic data types
2.3.1 Basic types are divided into three categories: the type of the stored integer (short (2 bytes) int (4 bytes) long (4 bytes; The defined number is followed by L or L; The default is just a number for int), a long long (8-byte number followed ll or LL), Stores non-integer types (also known as floating-point types), specifies an empty set of values, or does not specify any type of void type.
2.3.2 Character data type
Unlike the char type, the wchar_t type is called because it is a wide character type, storing two-byte character codes with a range of 0-65535.eg:wchar_t = L ' Z '; defines a variable letter and initializes it with the 16-bit code of the Z. The letter L in front of the character constant ' Z ' tells the compiler that this is a 16-bit character code value, and the wchar_t variable stores the Unicode code value. You can also use wchar_t letter (L ' Z '), or you can initialize an integer variable with a hexadecimal constant. wchar_t letter (0x5A);
2.3.3 Integer modifier
Define unsigned type is followed by U or u
eg:unsigned long mileage = 5UL;
2.3.4 Boolean type
A Boolean variable is also known as a logical variable, and type bool is considered an integer type. Its value is true and false;eg:bool colorisred = true;
2.3.5 Floating-point types
A floating-point constant must contain a decimal point or an exponent or both, and if not, it is considered an integer.
Double is 8 bytes, float is 4 bytes and is defined by adding F after the number and double without adding, by default.
There is also a long double type.
2.3.6 literal value
In C + +, constants of all types are called literals. Literals are values of a specific type.
2.3.7 defining synonyms for data types
The typedef keyword enables you to define your own type name for an existing type.
2.3.8 variables with a specific set of values
Sometimes it takes a variable with a finite set of possible values, a label that can effectively reference these values, and in C + + there is a tool for dealing with this situation, called an enumeration. eg
Enum Week{mon,tue,wed,thurs,fri,sta,sun} ThisWeek; This statement declares an enumeration type and a variable thisweek called Week, which is an instance of the enumeration type Week. It can only take a constant value specified between curly braces. The symbol names listed between curly braces are enumerators. In fact, each name of a date is automatically defined to represent a fixed integer value, such as mon=0,tue=1 ...
An enumeration constant can be assigned to it as the value of the variable ThisWeek, eg:thisweek= Thurs;
You can have enum Week{mon=1,tue,wed,thurs,fri,sta,sun} ThisWeek if you intend not to start from zero; the enumerator does not even need to have a unique value, such as Enum week{mon=2,tue=2, Wed,thurs,fri,sta,sun} ThisWeek; Because the type of thisweek is int, it accounts for 4 bytes and does not allow initialization of enumerators with function notation.
2. C + +