Home >Backend Development >C#.Net Tutorial >Is semicolon required as a separator between statements in C language?
#Must use semicolon as separator between statements in C language?
# Semicolons must be used as separators between statements in the c language.
In C programs, the semicolon is the statement terminator. Each statement must end with a semicolon. It indicates the end of a logical entity.
In C language, a semicolon is used as a mark for the end of a statement. If you accidentally write an extra semicolon in a C program, the semicolon may be regarded as an empty statement; or The compiler will generate a warning message because of this extra semicolon. It is often easy to find the extra semicolon according to the warning message.
For example:
If (x>b); b=x;
The extra semicolon will be interpreted as an empty statement, and the actual effect is:
If(x>b) {} b=x;
That is to say, when x> ;b, when executing an empty statement, b=x will be executed in any case.
If a semicolon is omitted in the C program, it means that the current statement has not ended, and an error will occur.
For example:
If(n<3) return log.date=x[0]; log.time=x[1]; log.code=x[2];
Because a semicolon is missing after return, it means that the statement has not ended, The actual effect is equivalent to:
If(n<3) return log.date=x[0]; log.time=x[1]; log.code=x[2];
Extended information:
1. Statement blocks in C language can contain statement blocks. Statement blocks in statement blocks are when. Make a simple statement to process.
2. If you want to write a statement block containing several expression statements and empty statements, you can use the following form: This is an example of a statement block, which contains four already understood statements, in order For assignment expression statements, null statements, division expression statements and bitwise negation expression statements.
Recommended tutorial: "C Language"
The above is the detailed content of Is semicolon required as a separator between statements in C language?. For more information, please follow other related articles on the PHP Chinese website!