Starting today, prepare to re-learn the C language. Although I understand the C language grammar, but always feel that understanding is not enough. For a variety of reasons, the previous study of C language has always been unable to persist, but this time hope that they can do better. Recommended here "C Language Depth Analysis" This book, if there are other good books, please recommend, thank you!
This article mainly summarizes the C language keywords, and some special keywords to introduce, for static, extern and other more complex keywords after the separate summary.
How many keywords are there?
The C keyword is not very fixed, unlike other languages. (About C89 and C99, will be written later in the article summary) C89 defined keywords have the following 32:
| Key Words |
meaning |
Key Words |
meaning |
Key Words |
meaning |
| Auto |
Automatic variables |
void |
Empty type |
Short |
Short-Integer variable |
| Int |
Integer variable |
Long |
Long-integer variable |
Char |
Character variable |
| Signed |
Signed type variable |
Unsigned |
Unsigned type variable |
Float |
Floating-point variables |
| Double |
Double-precision variables |
Register |
Register variable |
Static |
static variables |
| extern |
External reference variable |
Const |
Read-only variables |
Volatile |
Implicit mutable variables |
| Enum |
Enum type |
struct |
struct type |
Union |
Federated data Types |
| Switch |
Switch statements |
Case |
Switch Statement Branch |
Default |
Switch Default Branch |
| Do |
Loop body |
While |
Cycle conditions |
For |
Looping statements |
| Break |
Jump out of the current loop |
Continue |
End of the second cycle |
Return |
Return statement |
| If |
Conditional statements |
Else |
Conditional Negation Branch |
Goto |
Unconditional Jump |
| typedef |
Rename Type
|
sizeof |
Calculate Object Size |
|
|
C99 adds an inline (inline) keyword.
C11 Final Draft n1570 documentation also adds restrict, _alignas, _alignof, _atomic, _bool, _complex, _generic, _imaginary, _noreturn, _static_ Assert, _thread_local so some of the keywords, which of course is something.
Fastest variable: Register variable
This keyword declares that the variable is placed in the register as much as possible. This keyword is not always valid because of the size and number of registers. Use should be noted:
It is not declared that the Register is bound to be in the register.
register variable must be able to be the type that is accepted by the CPU register. means that the register variable must be a single value, and its length should be less than or equal to the length of the integral type.
The register variable may not be stored in memory, so the address of the register variable cannot be obtained with the fetch operator "&" .
sizeof is the key word
by The particularity of the use of sizeof (usually with parentheses) is often mistaken for a standard function, but it is actually a keyword. And this parenthesis is not always necessary, see the following code:
int i; 32-bit system sizeof (int)//4sizeof (i); 4sizeof int; Compile error sizeof I; 4
In other words, sizeof can omit parentheses when calculating the size of a variable, but it cannot be omitted when calculating the type size. Of course, the brackets are usually advocated.
Enum type
The enumeration types in the C language are generally defined as follows:
Enum enum_type_name{enum_const_1, enum_const_2,//... Enum_const_n;} Enum_var_name;
Where Enum_type_name is the enumeration type name and Enum_var_name is the variable name.
An enumeration constant can be explicitly assigned a value. If you do not assign a value, you will start with the constant that is assigned the initial value and then add 1, and if none are assigned, their values increment by 1, starting with 0. For example, to define an enumeration of three primary colors:
Enum primarycolor{RED,//0 green=10,//10 BLUE//11}color;
The main differences between enumerations and # define macros are:
#define宏常量是在预编译阶段进行简单替换, the enumeration constant determines its value at compile time.
In general, you can debug enumeration constants in the compiler, but you cannot debug macro constants.
Enumerations can define a large number of related constants at once, and a # define macro can only define one at a time.
typedef does not support basic type extensions
Here's an example of how typedef and # define are different:
A) #define INT int32; unsigned int32 i=10; OKB) typedef int int32; unsigned int32 i=10; Compilation error
An alias defined with # define is a good understanding because it is a direct replacement, but unfortunately, TypeDef cannot support such an extension.
About the basic keyword is introduced here.
This article is from the "Flying Cat" blog, be sure to keep this source http://flyingcat2013.blog.51cto.com/7061638/1564645
C Language Learning notes (i) keywords