Const 1. Limit synergistic variable can only be read Const I = 5; int J = 0; ... i = j; file: // illegally, causing compilation error J = i; file: // legal 2. must Initialization const I = 5; file: // legal const INT J; file: // illegally, causing compilation error 3. Reference constant extern const I; file: // legal Extern Const Int J = 10; file: // illegally, constant cannot be assigned again 4. Easy to perform type checking with the const method can make the compiler more about processing content. #define i = 10 Const long & i = 10; / * DapingGuo Reminder: Due to the optimization of the compiler, it is not assigned in the consissence of the memory, but it has been directly substituted in the future reference, There is no error in the subsequent code, in order to achieve the effect, specifically, with & i clearly gives I's memory allocation. But once you close all optimization measures, even if const line i = 10; it will also cause later compilation errors. * / char h = i; file: // There is no error CHAR H = I; file: // Compile warning, may cause an error assignment due to truncation. 5. Avoid unnecessary memory allocation #define string "abcdefghijklmn / n" const char string [] = "abcdefghijklm / n"; ... printf (string); file: // Assign the first memory Printf for String (String); File: // Distributes memory once, it is no longer allocated ... printf (string); file: // Assign the second memory printf (String); ... due to Const Definition The constant is seen from the perspective of the assembly, but the corresponding memory address is given, not the number as #define is the immediate number, so constants defined in the process of only one copy during the program run, and #define definition The constant has several copies in memory. 6. Init Value () can be initialized by a function of the constant (); payguo said: Assuming that when writing a program for the ROM, this statement will be invalid because the target code cannot be rewritten. However, it can be changed: Const Int & I = Value (); Implementation as long as the address of the i is in the ROM, you can implement: i is initialized by a function, and its value will not be modified. 7. Is the constant value of consts must not be modified? Observe the following code: const amount i = 0; int * p = (int *) & i; p = 100; by mandatory type conversion, the address is assigned to the variable, and the CONST constant value can be changed.