Variable three elements:
A variable has three basic elements, the name of the variable, the type of the variable, and the value of the variable.
so int a = 10; The variable is named a, the variable is stored in type int, and the value of the variable is 10.
Variables also have properties such as scope and storage type.
Variable scope and storage type
The scope has local variables and global variables. Local only works within a specific range. All variables work during the entire program run.
Storage type has auto (auto), static (static), register (register variable)
Auto variable auto is omitted by default, int a = 10; and auto int a = 10; is the same. The automatic variable allocates memory space dynamically, and the data is stored in the dynamic storage area.
Static variable statics, when the function is initialized, allocates space, and the data is stored in the static storage area, during the program run, the variable storage space will not be freed.
Pointer variable
Pointer variables in addition to the three elements above, there is a data type that the pointer points to.
int *p = &a;
The variable is named P, the type of the variable is a pointer type, the value of the variable is the address of a, and the pointer variable points to a data type of type int.
How to determine a variable type
Int (*p) (int,int); A pointer to a function.
is a pointer to a function entry.
Method of judgment: P is combined with * first, and is a pointer. When combined with (Int,int), the pointer points to a function that returns a value of int.
float *fun (int a); A function that returns a pointer value. As a function, the parameter is of type int and the return value is a float type pointer.
The judging method, fun and (int a) are combined as functions. The function return value is a float type pointer.
int *p[4]; An array of pointers. As an array, the storage type of the elements inside the array is the pointer type.
Judging method: P and [4] are combined, for an array, the array is stored in type int type pointer.
Float (*pointer) [4]; pointer variable pointing to a one-dimensional array. As a pointer to an array of length 4.
Judgment method: pointer and * Combine as a pointer. The pointer points to an array of length 4 with a float type.
Therefore, when judging a variable type, first look at the binding of the variable name, first and what the combination is what type of variable, first and the pointer is a pointer variable, and array is a combination of arrays. Then look at the other properties of the variable: the pointer has its pointer to the type, the array has its storage type, the function has return type and formal parameters, and so on.
How to determine the variable type of C language