Chapter 2 This is not a bug, but a Language Feature
At any time, if such a statement malloc (strlen (STR); is met, it can almost be determined that it is incorrect, malloc (strlen (STR) + 1 ); yes;
Summary-progress is the computer software engineering andProgramming LanguageAn important motivation for the gradual development of design art;
# Include <stdio. h> int main (INT argc, char ** argv) {const int one = 1; int I = 1; Switch (I) {Case One: printf ("1 ");}}
AboveCodeConst does not actually represent constants;
The break statement actually jumps out of the latest loop or switch statement;
When the operand of sizeof is a type name, parentheses must be added on both sides (which is often mistaken for a function), but parentheses are not required for the operand if it is a variable;
Some experts suggest note that two priorities in the C language are enough: multiplication and division are greater than addition and subtraction, and brackets are added when designing other operators;
Operator combination: it is the arbitration. When several operators have the same priority, it determines which one to execute first;
All the value assignment operators (including those conforming to the value assignment) have the right combination. (They are also combined with the single object operator );
# Include <stdio. h> # include <string. h> char * F () {char Buf [10]; strcpy (BUF, "abcdefg"); Return Buf;} int main (INT argc, char ** argv) {printf ("% s", F ());}
The above Code cannot print the expected value, because the Buf is a local variable. At the end of the function, no one knows what the address pointed to by this pointer is because the variable has been destroyed;