------- iOS training, Android training, Java training , and looking forward to communicating with you! ----------
Speaking of C language many people will think of the beginning of learning programming when the love and hate, although the C language is an ancient language, but does not hinder people's use of it. The most important features of C language are: Strong function, easy to use and flexible. C Compiled program for grammar check is not as strict as other high-level language, this gives programmers leave "flexible room", but still because of this flexibility to the debugging of the program brought a lot of inconvenience, especially for beginners of C language, often out of some even they do not know where the wrong mistake. Looking at the wrong program, I do not know how to change, I see Li Mingjie Teacher's video with their own see other information encountered several errors, remind yourself not to do again!
1. When writing identifiers, the difference between uppercase and lowercase letters is ignored.
int Main () { int a=5; printf ("%d", A); return 0 ;}
The compiler considers a and a to be two different variable names, and displays an error message. C considers uppercase and lowercase letters to be two different characters. Traditionally, symbolic constant names are capitalized, and variable names are denoted in lowercase to increase readability.
2. Ignoring the type of variable and doing illegal operation
int Main () { float A, b; printf ("%d", a%b); return 0 ;}
% is the remainder operation, and A/b is obtained. Integer variables A and B can be used for redundancy operations, while real variables do not allow "redundancy" operations.
3. Confuse character constants with string constants
Char c;c="a";
Here, the character constants and string constants are confused, character constants are single characters enclosed by a pair of single quotes, and string constants are sequences of characters enclosed in double quotation marks. c Specifies "\" as a string end flag, which is automatically added by the system, so the string "a" actually contains two characters: ' A ' and ' s ', and assigning it to a character variable is not possible.
4. Ignore the difference between "=" and "= ="
In many high-level languages, the "=" symbol is used as the relational operator "equals". As can be written in the basic program
if (a=3) then ...
But in C, "=" is an assignment operator, and "= =" is a relational operator. Such as:
if (a==3) a=b;
The former is for comparison, whether a is equal to 3, and the latter indicates that if a and 3 are equal, the B value is assigned to a. Because of the habit problem, beginners often make such mistakes.
5. Forget to add a semicolon
Semicolons are an integral part of the C statement and must have a semicolon at the end of the statement.
A=1b=2
At compile time, the compiler does not find a semicolon after "a=1", and the next line of "b=2" is also part of the previous line of statements, which can cause syntax errors. Sometimes, if you don't see an error in a row that you've identified as wrong, you need to see if the previous line missed the semicolon.
{ z=x+y; T=z/; printf ("%f", T);}
For compound statements, the last semicolon in the last statement cannot be ignored (this is different from Pascal).
6. Extra semicolon
For a compound statement, such as:
{ z=x+y; T=z/; printf ("%f", t);};
You should not add a semicolon after the curly braces of a compound statement, otherwise it will be superfluous. Another example:
if (a%3==0);
i++;
This is if 3 is divisible by a, then I plus 1. However, because if (a%3==0) after the addition of semicolons, the IF statement to the end, the program will execute the i++ statement, regardless of whether the 3 divisible a,i will automatically add 1. Again such as:
for (i=0;i<5; i++); { scanf ("%d",&x); printf ("%d", x);}
The intention is to enter 5 numbers successively, and then output each number after entering it. Because a semicolon is added to the for () to make the loop body an empty statement, you can enter only one number and output it.
7. Forget add address Operator "&" when input variable
int a,b;scanf ("%d%d", b);
This is not legal. The function of scanf is to store the value of a and B in the memory address according to A and B. "&a" refers to the address in memory of a.
Dark Horse programmer-some common mistakes in C language