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;
Conclusion-progress is an important driver for the gradual development of computer software engineering and programming language design art;
[Cpp]
# Include <stdio. h>
Int main (int argc, char ** argv)
{
Const int one = 1;
Int I = 1;
Switch (I ){
Case one: printf ("1 ");
}
}
The above code compilation fails, indicating that const does not actually represent a constant;
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 );
[Cpp]
# 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;
From CodeBlog