This is the first summer vacation of the university. I want to study hard this summer and review the knowledge of the previous two semesters. Therefore, I decided to read "C traps and defects" again. this is indeed a very good book. I think it is one of the books that students must read. The following are my reading notes that will be constantly updated, I hope it will be helpful for learning C.
Chapter 1
1.It doesn't make sense to isolate a single character in the program. It only makes sense to combine context.
You can use a Write Program as an essay. Each "symbol" is a basic component unit of a program. It is equivalent to a word in a sentence, and then a sentence is composed of words.
The statement is a program. A symbol is composed of character sequences. Different symbols of character sequences in different contexts have different
. The blank characters (spaces, tabs, and line breaks) between symbols in the C language will be ignored.
2.=,&, |Not equal to =,&&, |.
In C, = represents the value assignment operation, and = represents the comparison operation. & represents the address operation or bitwise operation. & represents the logical operation (and); | represents the bitwise operation, | indicates
Logical operation (OR ). This is different from a write language. In some languages (such as Pascal), = is not only used as the value assignment operator, but also as the comparison operator. & and |
Do not use and or. = And = are the most representative. For example, the following statement:
If (x = y) <br/> Foo ();
The intention is to compare the size of X and Y. If the values are equal, run the foo function. However, assign the value of Y to X and check whether the value is 0. To avoid this situation, some programmers will
When comparing a constant with a variable, the constant is written on the left side of the comparison symbol. If the symbol is incorrect, an error is returned. The two variables must be compared without the compiler warning.
Comparison, namely:
If (x = y )! = 0) <br/> Foo ();
3."Greedy ".
The greedy method, also known as the Big Mouth method, is a method for distinguishing between multi-character symbols in C language. The rule is simple: each symbol should report as many symbols as possible. In addition to strings and words
Character constant. There cannot be blank spaces in the middle of the symbol. For example, a --- B is the same as a -- B, but different from a--- B. In this example, a ++ B indicates a ++ B. Why?
Isn't it a ++ B? This is because a ++ cannot be left.
4.Character represents the pointer between a number and a string pointing to the starting character of an unknown array.
The single quotation marks and double quotation marks in C language have different meanings. In some cases, if the two are mixed, although the compiler will not detect errors, it will produce unpredictable knot at runtime.
Result. A character caused by single quotes actually represents an integer. The value of an integer corresponds to the Sequence Value of the character in the character set used by the compiler. 'A' indicates 97 (decimal ). Double Guide
The string that is caused by the number represents a pointer to the starting character of an unknown array. The array is initialized by characters between double quotation marks and an extra binary character '/0.
For example:
Printf ("Hello World ");
And
Char H [] = {'h', 'E', 'l', 'l', 'O', '', 'w', 'O ', 'R', 'l', 'D', '/0 ');
Printf (h );
Is equivalent. If you enter a language in the program
Char * P = 'a';, an error will be reported during compilation. Because 'A' is not a character pointer. However, the compiler does not check the function parameters, especially the parameters of the printf function,
If you use printf ('/N'); to replace printf ("/N");, unexpected errors will occur.