Variable declaration in C Language
Int I, j, k = 0; // defines three integer variables: char c; // defines an integer c. Of course, multiple variables in a declaration statement can be separated and written, the Declaration above is equivalent to int I = 0; int j = 0; int k = 0; char c; the declaration of any variable can be limited by the const qualifier. The specified value cannot be modified, for example, # include <stdio. h> int main () {const int num = 20; num = num + 2; printf ("% d", num); return 0;} error: l-value specifies const object # include <stdio. h> int main () {volatile const int num = 20; int * p = & num; * p = 10; printf ("% d", num); return 0 ;}
Result: 10 volatile prevents the compiler from optimizing the code and reminds the compiler that the variables defined after it may change at any time. Therefore, each time the compiled program needs to store or read the variable, data is read directly from the variable address. If there is no volatile keyword, the compiler may optimize reading and storage, and may temporarily use the value in the register. If this variable is updated by another program, it will be inconsistent.