By Andrew Koenig, translated by Gao Wei, reviewed by Wang Xin
C traps and pitfalls
Andrew Koenig and C ++
Absolute classic
1. Greedy method in lexical analysis: each symbol should contain as many characters as possible
2. If the first character of an integer constant is 0, it is regarded as an octal value. 0100 = 64, not binary
3. printf ("Hello \ n"); with Char Hello [] = {'h', 'E', 'l', 'l', 'O ', '\ n', 0}; printf (Hello); equivalent
4. function pointer int (* FP) (); can be abbreviated as int FP ()
5. Simple priority: calculation> relationship> shift> Logic
6. It is best to write a semicolon next to struct a {...}. Some compilers will not report errors.
7. else always matches the nearest if in the same bracket
8. The C language only has a one-dimensional array, and the size of the array must be determined during compilation.
9. Multi-dimensional arrays are simulated by one-dimensional arrays.
10. int A [32] [11]; meaning that A is an array with 32 Elements and each element has 11 integer variables.
11. for int A [32] [11]; If int I = A [4] [5]; you can write it as I = * (a + 4) + 5 ); or I = * (a [4] + 5 );
12. int A [32] [11]; int (* AP) [11]; ap =;
13. As a function parameter, the array name is converted to a pointer pointing to the first element of the array.
14. extern char * P; different from extern char P [];
1-C traps and defects 1 in the computer classic book series