The biggest feature of the C language is: functional, convenient and flexible. The C-compiled procedures are not as strict, so that the programmer has left "flexible room", but because this flexibility has brought a lot of inconvenience, especially for beginner C language. When people say, they often don't know where they are wrong. Looking at the wrong procedure, I don't know how to change, I have accumulated some errors that C-programmatically committed the mistakes by learning from C, and wrote to the students for reference.
1. When writing the identifier, the difference between case the case is ignored.
Main () {Int a = 5; Printf ("% d", a);}
The compiler puts A and A as two different variable names, and displays the error message. C believes uppercase letters and lowercase letters are two different characters. Habitually, symbol constant names, variable names are smaller, to increase readability.
2. Ignore the type of variable, which is not legal operation.
Main () {float a, b; printf ("% d", a% b);}
% Is the rest of the operation, get the entire number of A / B. Integer variables A and B can be submitted, while the real variables do not allow "resufficient" operations.
3. Confused character constants with string constants.
CHAR C; C = "a";
It is confused here to confuse the character constant and string, and the character constant is a single character enclosed by a pair of single quotes, and the string constant is a pair of double quotes enclosed characters. C specifying the "/" string end flag, which is automatically added by the system, so the string "a" actually contains two characters: 'a' and '/', which gives it a character variable Yes no.
4. Ignore the difference between "=" and "==".
In many advanced languages, use "=" symbol as the relational operator "equal". If you can write in the BASIC program
IF (a = 3) Then ...
However, in the C language, "=" is an assignment operator, "==" is a relational operator. Such as:
IF (a == 3) a = B;
The former is compared, whether A is equal to 3, and the latter means that if A and 3 are equal, the B value is assigned to a. Because of habit, beginners tend to make such mistakes.
5. Forget the semicolon.
The semicolon is an indispensable part in the C statement. There must be a semicolon at the end of the statement.
A = 1B = 2
When compiling, the compiler did not find the semicolon after "a = 1", and the next line "B = 2" also as part of the previous line statement, this will appear syntax errors. When it is wrong, sometimes there is no mistake in the wrong line that is pointed out, it is necessary to see if the last line will miss the semicolon.
{Z = x y; t = z / 100; Printf ("% f", t);}
For a composite statement, the last semicolon in the last statement cannot ignore the unwritten (this is different from the PASCAL).
6. Add a number of semicolons.
For a composite statement, such as:
{Z = x y; t = z / 100; Printf ("% f", t);};
The composite statement should not be added to the semicolona, otherwise the snake will be added.
As another example:
IF (a% 3 == 0); i ;
This is if 3 except A, then i plus 1. However, since the semicolon is added more than if (a% 3 == 0), the IF statement is over, the program will execute the I statement, regardless of whether the entire A, i will be automatically added 1.
Rethlean:
For (i = 0; i <5; i ); {scanf ("% D", & x); Printf ("% d", x);} It is intended to enter 5 numbers, once a maximum number It outputs it. Since the FOR () adds a semicolon to make the cyclic body becomes a null statement, only one number can be entered and output it.
7. Forget the address operator "&" when entering the variable.
INT A, B; Scanf ("% D% D", A, B);
This is not legal. The scanf function is to store the value of A and B in accordance with A and B's address in the memory. "& A" refers to the address in memory.
8. The way to enter data does not match the requirements.
1SCANF ("% D% D", & A, & B);
When entering, you cannot use a comma to make a separator between two data, such as the input is not legal: