C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)

Summarize the commonly used keywords first, and explain and supplement them one by one in the later study.

auto (automatic) break (interrupt loop) switch …… case char (character type) const (define constant variable) continue (continue to loop) default
do……while double (double precision floating point type) if …… else enum (enumeration Type) extern (external variable declarator) float (single-precision floating-point type) for goto
int (integer) long (long integer) register (register operator) return (return) short (short integer) signed (signed , Usually omitted) sizeof (calculation string length unit: byte) static (static variable) struct (structure) typedef (type delimiter, can be understood as type renaming) union (union/common body) unsigned (unsigned) ) Viod (none) volatile

Here are a few selections I will give a brief introduction:
extern:
C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)
C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)
As shown in the figure, I created two .c files, defined the document in the "test auxiliary.c" file, and used it in the test C keyword introduction file. When documenting, you can use extern to declare external symbols and quote them directly without repeating definitions.
typedef:
Example:
At this time, we define an unsigned integer
int main()
{
unsigned int a = 20;
printf("%d\n", a);
return 0;
}
As the above operation, the unsigned int type symbol is too much Complicated, at this time we can use typedef to redefine the name of the unsigned int type symbol, as follows
typedef unsigned int u_int; // Note: Typedef must be followed by the type symbol followed by a name you want
u_int b=20;
At this time b and a are the same type of
static: 1. Extend the life cycle of local variables 2. Change the scope of global variables 3. Static modifier function
1. As shown in the figure:
C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1) C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)
We input such a function body, and the output result is 5. A 1, because a is a local variable, when it goes out of its own running space, the life cycle of a ends, so when the main function calls the test function again, the value of a changes back to 0, so 5 times Output, the value of a is 1;
When static is added in front of int a, the output result becomes 1, 2, 3, 4, 5; after debugging, it is found that the static statement is executed only once, that is, when the main function calls the test function for the second time, it jumps directly After the static statement, execute a++, the value of a is not set to 0 again; this shows that the static keyword can extend the life cycle of local variables and has a memory function.
C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)
2. Take the extern example again. After we add a static before the global variable document in the test assistant file, and compile the program again, we will find the following error (unable to parse external instructions). Static invalidates instinctively called global variables, which proves that it changes the scope of global variables; static global variables can only be used inside the original file where they are located
C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)

C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)
3. When a function is modified by static, it is similar to modifying a global variable. A function itself has an external link attribute. After being modified by static, the function body can only be used in the original file where it is located;
C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)
operate as shown in the figure above, in the test auxiliary file The test function is defined in the test C keyword introduction, and the test function is quoted in the introduction of the test C keyword. Through the extern declaration, the function can successfully run and output 1, 2, 3, 4, 5, but after adding the static keyword in front of test() , The system will report the following error, the test function cannot be found; at this time, static changes the connection attribute of the function;
C language-a summary of commonly used keywords in C language (novices please feel free to enlighten me) (1)

Guess you like

Origin blog.51cto.com/15126924/2656501