The class is already 11th days, and the C language syntax is almost over. The rest is only the scanning operation. There are 32 keywords in C language. Old Liu first listed these keywords, and then did not talk about them at ordinary times.
C language keywords: void int char short long double float unsigned signed
If else do while sizeof auto register const static Enum
Typedef return break goto continue swich struct Union
Case default extern for volatile
Extern: no memory allocation. It is declared as an external variable only.
Variables frequently changed by auto are not needed.
The register variable is used for frequently accessed data to speed up access, but the number is limited.
Volatile indicates that variables are related to hardware and do not want to be optimized by the compiler.
Type Def rename the variable
The const read-only variable is generally used as a pointer.
1 #include<stdio.h> 2 3 int main() 4 { 5 int i = 10; 6 int j = 20; 7 8 const int * p1 = &i; 9 int * const p2 = &i;10 11 *p1 =20;// err12 p1 = &j;//ok 13 *p1 = 21;//err 14 *p2 = 20 ; // ok15 p2 = &j ; err 16 }
For example, in the eighth row, if the const is closest to the next user, the content in * P is immutable. The eighth row can also be written as int const * P1 = & I; const, which is generally used as a function parameter.
1 # include <stdio. h> 2 # include <assert. h> 3 4 int mystrcpy (char * DEST, const char * Source) 5 {6 assert (source! = NULL); // asserted 7 while (* Source) 8 * DEST ++ = * Source ++; 9} 10 11 int main () 12 {13 char * P = "Hello World"; 14 char * P2 = NULL; 15 char data [1023] = {0}; 16 17 mystrcpy (data, P2 ); 18 printf ("data is % s \ n", data); 19 20 21}
Note that assertions are used here.
Void * P does not know what type of address to store. It is generally used by implicit type conversion.
Macro definition: # define is just a simple replacement. So try to use ()
To prevent header files from being repeatedly contained, use # ifndef A # define a # endif to make code and platform independent use # ifdef # else # endif
To annotate the code, use # If 0/1 # else # endif
1 #include<stdio.h> 2 #include"bunfly.h" 3 #include"hello.h" 4 5 #if 1 6 int main() 7 { 8 printf("i am main\n"); 9 hello(); 10 bunfly();11 }12 #else 13 int main()14 {15 printf("hello world \n");16 17 }18 #endif
In the afternoon, Lao Li gave us interview skills and simulated interviews with two people. I feel that I have no advantage in my interview now. Strengthen communication skills. Submit your resume on Monday.
11th days: Keywords of C Basics