I. global variables and local variables
(1) global variables are defined outside the function, and local variables are in the function body. They have different scopes and lifecycles.
2. struct
(1) It defines that the struct will not allocate memory. Only when the struct defines a variable will it allocate memory for this variable. The address of the first member is the address of the struct variable.
Int main (INT argc, const char * argv []) {// structure format struct person {int age; char * Name ;}; // defines the variable struct person P1; // assign values. There are multiple assign values, such as struct person P2 = {10, "Tom"}; p1.age = 28; p1.name = "Andy "; // access printf ("% s \ n", p1.name); Return 0 ;}
(2) The allocated space is a multiple of the largest byte member variables. For example, in the above struct, Int Is 4 bytes, char * is 8 bytes, total is 12 bytes, but to be an integer multiple of the maximum byte member, each struct variable is 16 bytes in total.
(3) There are many other ways to define struct variables. In addition to the above method, you can add a P before the semicolon to define a variable while defining the struct. Another method is the anonymous struct, which can only define variables at one time, because it cannot be reused in the future.
(4) struct array. It is defined and initialized in batches when struct variables are defined. For example, struct person P [3] = {{},{},{}};. But it is rarely used. Struct Arrays can only be initialized when they are defined.
(5) The struct is the same as the array. Variables cannot be defined first and then assigned values.
(6) pointer to the struct. Because it is directed to the struct, the definition method is struct person * P. P = & P1; point this pointer to P1. The key is how to set the value. (* P). Age can be used, but p-> age is more common.
(7) struct, of course, can be nested.
(8) The largest feature of struct compared to arrays is that it can store different types of values, while Arrays can only be the same type of values.
Iii. Enumeration Variables
Int main (INT argc, const char * argv []) {// do not use a value. All values are devil values. // int gender = 0; // define an enumeration // we can give man = 100, then the following value is incremented at a time, that is, woman is 101 Enum gender {Man, woman }; // use and define an enumerated variable gender1 Enum gender gender1 = man; return 0 ;}
[Xcode C-5] structure, global local variables and enumeration variable knowledge