Reading Notes-C traps and defects, Reading Notes-c traps
To participate in the C language project, the author had to regain the C language (previously C ++, or C ++ for convenience ).
We recommend that you look at the C traps and defects (C traps and pitfalls), so curious to start the book's reading Journey.
I decided to record important knowledge points and error points in the book so that I can review them and learn from others ~~ Let's just move on to the next step.
Chapter 1: lexical traps
1 if (x> big) big = x; 2 can be written as: 3 if 4 (5x6> 7 big 8) 9 big10 = 11x12;
In fact, we have already involved the encoding. For example, the C standard requires that space characters be used for alignment, and the overly long encoding will be divided into two lines of books.
Of course, these so-called blank spaces are ignored. Otherwise, the compiler will not be able to understand the program's intent...
2. in the lexical analysis, the author points out that if/is the first character read to judge the next symbol, And/is next to *, then the context is ignored, both characters are treated as a symbol/*, indicating the beginning of a comment.
The following problems may occur:
Y = x/* p;
The statement is to divide x by p to indicate the point value, and the result is assigned to y. However,/* is interpreted as a comment, so the statement directly assigns x to y.
In fact, writing (* p) can be avoided. Y = x/(* p );
This error may occur. Fortunately, the current IDE comments will change color and should be easily noticed.
3. Character and string:
Every C language knows that single quotation marks indicate characters, while double quotation marks indicate strings.
In fact, a single character caused by single quotes actually represents an integer, which corresponds to the Sequence Value of the character set used by the compiler.
Generally, the ASCII character set is used, that is, 'A' is exactly the same as 97 (decimal.
Double quotation marks indicate a pointer to the starting character of an unknown array, the array is enclosed by a string between double quotes + an extra binary value of 0 '\ 0' (C is often used to indicate the end of initialization.
Example:
1 printf ("hello world \ n"); 2 and 3 char hello [] = {'h', 'E', 'l', 'l', 'O ', '', 'w', 'O', 'R', 'l', 'D', '\ n', 0}; 4 printf (hello); is equivalent
It is true that the above Code is run, but it is more readable to write hello [] as follows.
Char hello [] = {'h', 'E', 'l', 'l', 'O', '', 'w', 'O ', 'R', 'l', 'D', '\ n',' \ 0 '};
4. The book also mentions that the storage space of INTEGER (16/32 bits) can contain multiple characters (8 bits), so some compilers allow a String constant to include
Multiple characters. For example, 'yes' replaces "yes ".
Based on the integer nature of a single character, the author made an experiment:
1 int t1='a';2 printf("%d\n", t1);3 int t11='aa';4 printf("%d\n", t11);
Output result:
97 is the asc code value of 'A', which is easy to understand. However, the value of 'A' 24929 may be related to the compiler and storage method, which is not understood by the author for the moment, you can comment on this topic ~~
The first chapter focuses on these points. We look forward to the second chapter!