Enum TypeI. Scope of applicationAn enumeration type can be used to define a variable when it has only a few possible values.
Ii. Rules of Use1. After the enumeration variable is established, the enumeration variable is assigned a value that requires the same enumeration type. 2, if the type is inconsistent, you need to use force to replace the enumeration constant with the same type assigned to the enumeration variable. 3, enumeration constants, enumeration types of variables can be directly carried out in various forms of relational operations. 4. Enumeration constants are constants, not variables, so enumeration constants cannot be assigned.
third, expression formatenum Enum type name {Enum constant 1, enumeration constant 2, ... , enumeration constant n};
ArrayAn array is a set of data variables of the same type that are stored in memory once in a row.
one or one-D arrays1. Format:definition: Data type array name [constant expression];Initialize: Array name of data type [constant expression]={initial value 1, initial value 2, ... , initial value n};2, the address of the array:for array a[n] array address: a+n*sizeof (int)
two or two-D arrays1. Format:definition: Data type array name [constant expression 2] [constant expression 1];(where the constant expression 1 is the number of 1th dimension elements, the constant expression 2 is the number of the 2nd dimension element)initialization: Array name of data type [constant expression 2] [constant expression 1]= initial value table;2. Note:the initial number of each dimension cannot exceed the number of corresponding dimension elements;only the number of the highest dimensional elements can be omitted;3, in-memory address calculation formula:A[i][j] Arrangement position = 1th dimension size n*+j+1;A[i][j] Address =a start address + (1th dimension size n*i+j) *sizeof (data type) Third, note:The value of the subscript expression starts at 0You can omit the size of an array only if you initialize it when you define the array. You cannot drop an array and copy the whole to another array.
Pointersthe type of variable used to store the address of the memory unit.
First, Format1. Definition:data type * variable name;2. Initialize:data type * Pointer variable name = initial address expression;
Second, note1, cannot assign a non-address variable, variable and meaningless actual address to the pointer variable expression;2. When an initialized pointer is used to assign a value to another pointer, the type must be the same;3. The void type pointer can store any type address, but assigns the address of a void type to a pointer variable of non-void type, using a type cast. third, pointer arithmeticThe operation of the pointer is actually the operation of the address, with assignment, value, arithmetic, subtraction, comparison, and so on. 1. * Arithmetic: Used to define pointer variables, which means to access the contents of the object referred to by the pointer. 2, & operations: Used to make the type of the address is the same as the variable type of action, representing the address of the variable Iv. pointers and Arrays1, pointer array: The pointer variable is an array of elements, and each element of the pointer array is a pointer variable of a uniform type, you must first assign a value and then refer to it. format: type name * array name [subscript expression];2. Array pointers: pointers to arrays, type to match when assigning values to array pointers. format: type name (* pointer name) [subscript expression];
V, pointer constants and constant pointers1. Pointer constantFeatures: A const modifier is used before the pointer;The defined pointer is a constant of a pointer type. format: Data type * Const pointer name = variable name;2. Constant pointerfeature: Use const modifier before data type;A pointer variable that is defined is a pointer to a constant. format: const data type * Pointer variable = variable name;orData Type Const * Pointer variable = variable name;
Structure and Union First, the structure a whole type that combines different data types. 1, Characteristics: The key word for the struct;The size of the occupied memory is the sum of the memory size of each member;2. Format:struct struct type name {data type 1 member name 1;data type 2 member name 2;..... }use: struct type name structure variable name ={member name 1 value, member name 2 value, ... The value of the member name n};3. Note: When initializing struct variables, the order of the member Values table should be the same as the order in which they were defined;Once you define a struct variable, each member can only be initialized individually.
Ii. Unitedis a data type that is similar to a struct type, where several different types of data can be stored in the same piece of memory. 1, Characteristics: The key word is union;The total memory size is the maximum amount of memory that is occupied by each member. 2. Format:Union struct type name {data type 1 member name 1;data type 2 member name 2;..... } use: struct type name structure variable name ={member name 1 value, member name 2 value, ... The value of the member name n};3, note: The memory arrangement starts from the low address, follows the principle of "low address low byte, high address high byte".
C + + "construct data type"