Speak the keywords, identifiers, and operators of the C + + language before explaining the data type.
Key Words
Keyword is a C + + predefined words, we define variables are not easy to use, the common keywords are: ( understand )
Asm |
Double |
New |
Switch |
Auto |
Else |
operator |
Template |
Break |
Enum |
Private |
This |
Case |
extern |
Protected |
Throw |
Catch |
Float |
Public |
Try |
Char |
For |
Return |
typedef |
Class |
Friend |
Register |
Union |
Const |
Goto |
Short |
Unsigned |
Continue |
If |
Signed |
Virtual |
Default |
Inline |
sizeof |
void |
Delete |
Int |
Static |
Volatile |
Do |
Long |
Struck |
While |
Identifier
An identifier is a sequence of characters used to identify variables, functions, data types, and so on.
Identifiers can consist of uppercase letters, lowercase letters, underscores (_), and numeric 0~9, but must be preceded by a lower case letter or an underscore (_).
For example, name and name represent two different identifiers.
operator
Operators are symbols used to perform operations, such as + 、-、 *,/, and so on.
Next is the point: * * *
Basic data type Detailed
Id |
Category |
Key words |
Description |
1 |
Data type |
bool |
Basic Type--Boolean type |
2 |
Data type |
Char |
Basic type--character type |
3 |
Data type |
wchar_t |
Basic type--wide character type |
4 |
Data type |
Double |
Basic type--solid type |
5 |
Data type |
Float |
Basic type--floating-point type |
6 |
Data type |
Int |
Basic type--integral type |
7 |
Data type |
Long |
Basic type--long integer type |
8 |
Data type |
Short |
Basic type--short integer type |
9 |
Data type |
Signed |
Basic type--Signed integral type |
10 |
Data type |
Unsigned |
Basic type--unsigned integral type |
11 |
Data type |
False |
Boolean type--False value |
12 |
Data type |
True |
Boolean Type--truth |
13 |
Data type |
Enum |
base class Type-enum type |
14 |
Data type |
Union |
Base class type-union type |
15 |
Data type |
struct |
base class type-struct type |
16 |
Data type |
TypeName |
This keyword is used to represent a common type when defining a template. |
17 |
Data type |
typedef |
Alias--Used to alias data type |
18 |
Data type |
sizeof |
Length calculation-The length of bytes occupied by the calculation type |
19 |
Condition control |
Switch |
Switch Branch statement |
20 |
Condition control |
Case |
Switch Branch statement--Conditional judgment |
21st |
Condition control |
Break |
Conditional interrupts |
22 |
Condition control |
Default |
Switch Branch statement--default branch |
23 |
Condition control |
Continue |
Skip Continue |
24 |
Condition control |
Do |
Cycle |
25 |
Condition control |
Else |
Branch |
26 |
Condition control |
For |
Cycle |
27 |
Condition control |
Goto |
Jump |
28 |
Condition control |
If |
Branch |
29 |
Condition control |
While |
Cycle |
30 |
Condition control |
Return |
Return |
31 |
Semantic retouching |
Auto |
Declaring a variable's lifetime is automatic, and the variable defined in any class, struct, enumeration, union, and function is not treated as a global variable, whereas a variable defined in a function is considered a local variable. This keyword doesn't write much, because all variables are auto by default. |
32 |
Semantic retouching |
Const |
The const-modified items are protected against accidental changes and can improve the robustness of the program.
- A modifier function parameter (non-intrinsic type), which is a const reference pass.
- The decorated return value (the return value is a pointer type) can only be assigned to variables of the same type.
- Modifier variables
- Modifier pointer variable
|
33 |
Semantic retouching |
extern |
Declare and reference this variable as an external variable that exists in a file in the project. |
34 |
Semantic retouching |
Friend |
Declare a friend function or class. |
35 |
Semantic retouching |
Inline |
The declaration defines an inline function, which embeds the called code into the main function at compile time. |
36 |
Semantic retouching |
Private |
access Rights : the class private function and the data member's label. Private members are accessible only to member functions of the class itself. Inherit permissions : All member access permissions for the parent class become private in the subclass. |
37 |
Semantic retouching |
Public |
access Rights : class public functions and data members are marked. can be accessed by object or class name. inherited permissions : The access rights of the parent class members are unchanged in the subclass, and are still their original permissions. |
38 |
Semantic retouching |
Protected |
access Rights : class-protected functions and data members are marked. Protected members are accessible only to member functions of the class and to member functions of their derived classes. inherited permissions : The public member access rights of the parent class become protected in the subclass, and the protected members and private members of the parent class maintain the same permissions on the child class permissions. |
39 |
Semantic retouching |
Register |
This keyword commands the compiler to increase efficiency by having variables in the CPU internal registers as much as possible, rather than through memory addressing. |
40 |
Semantic retouching |
Static |
Process-oriented static keyword To define a static global variable :
- The scope is in this file and is not visible in other files.
- Uninitialized static global variables are automatically initialized and automatically initialized to 0 by the program.
- Static global variables allocate memory in the global data area.
Defining static Local variables
- The scope is a function in this file, initialized only once, and the value is persisted to the next call when the function is called multiple times, until the new value is assigned next time.
- Static local variables are typically initialized at the declaration and, if not explicitly initialized, are automatically initialized to 0 by the program.
- Static local variables allocate memory in the global data area.
Defining static Functions
- Only visible in the file it declares.
Object-oriented static keyword Defining static data members for a class
- Static data members are treated as members of the class, all objects share access, and their values can be updated.
- Static data members comply with PUBLIC,PROTECTED,PRIVATE access rules like normal data members.
- Static data members are stored in the global data area. Static data members are defined when space is allocated.
- The static data member initialization format is as follows: Data type >< class name >::< static data member name >=< value
- Two ways to access static data members:
Class object name >.< static data member name or Class type name >::< static data member name > static data members advantages (compared to global variables)
- Static data members do not enter the program's global namespace, so there is no possibility of conflicts with other global names in the program.
- Information hiding can be implemented. A static data member can be a private member, while a global variable cannot.
Defining static functions for a class
- Static functions are treated as members of the class, and all objects share access.
- You need to add the static keyword when declaring inside a class without adding the static keyword when you define it outside the class.
- A non-static member function can arbitrarily access static member functions and static data members.
- It does not have the this pointer, it cannot access non-static data members that belong to a class object, and cannot access a non-static member function, it can only invoke the rest of the static member functions.
- Call Format:
Class name >::< static member function name > (parameter table) |
Lesson three C + + data types