Chapter II variables and basic types
1. The basic built-in types include arithmetic types and empty types, and arithmetic types are divided into two categories: integer (including character and Boolean type) and floating point type;
2. The value of the Boolean type (BOOL) is true (true) or False (false);
3. Literal constants: Each literal constant corresponds to a data type, and the form and value of the literal constant determines its data type.
A character enclosed in single quotation marks is a char literal, with 0 or more characters enclosed in double quotation marks, which are string literals;
20 Shaping literals
' A ' character literals
"Hello World" or "" will have string literals
' A ' represents an individual character a, while "a" represents an array of qualifying characters, one is the letter A and the other is a null character.
4. The basic form of the variable definition: The first is the type specifier, followed by one or more variable names (variable names separated by commas), and finally end with a semicolon;
1 int 1, i,k; // I,j,k is the same as int type, I is initialized to 1;
5. Variable declaration and definition: declaration is to make the name known to the program, a file if you want to use a name defined elsewhere must contain a declaration of the name, and the definition is
Creates the entity associated with the name, the keyword extern. Any declaration that contains an explicit initialization becomes a definition;
1 extern int i; // declaring I rather than defining 2 int i; // declare and define 3 extern int 1; // definition
6. Identifiers consist of letters, numbers, underscores, must start with letters or underscores, variable names to reflect the actual meaning, the variable name is generally lowercase, the custom class name usually begins with an uppercase letter,
If it consists of multiple words, there should be a clear distinction between the words.
1 int index; 2 Char " ABC " ; 3 int Sales_item; 4 int Carbridegesort;
Also attached is a basic data type understanding and conversion of small programs:
1 //Type Conversion Example2 3#include <iostream>//header File4 using namespaceStd//with Std::cout a function;5 6 intMain ()7 {8 BOOLb = the;9cout<<"B ="<<b<<endl;//B = 1Ten One inti =b; Acout<<"i ="<<i<<endl;//i = 1 - -i =3.14; the DoublePI =i; -cout<<"pi ="<<pi<<endl;//pi = 3.0 - -UnsignedCharc =-1; +cout<<"C ="<<c<<endl;//if char accounts for 8 bits, C is 255 - +SignedCharC2 = the; Acout<<"C2 ="<<c2<<endl;//if char occupies 8 bits, C is undefined at -System"Pause"); -}
C + + Primer notes (2) Chapter II variables and basic types