Home > Article > Backend Development > What are the six basic statements in C language?
The six basic statements of C language are: 1. Expression statement; 2. Label statement; 3. Loop statement; 4. Compound statement; 5. Jump statement; 6. Selection statement.
#The execution part of a C program is composed of statements. The functions of the program are also implemented by execution statements.
C statements can be divided into the following five categories:
1. Expression statement
2. Label statement
3. Loop statement
4. Compound statement
5. Jump statement
6. Select statement
The following are detailed descriptions:
Expression statement
The expression statement consists of an expression plus a semicolon ";".
Its general form is: expression; executing an expression statement is to calculate the value of the expression and perform side effects.
For example: Increment 1 statement, i value increases by 1.
i ; is to calculate i first and then add 1.
i; is to first increase the i value by 1 and then perform the operation.
Including empty statements and function call statements, they are all expression statements.
Label statement
There are three types of label statements:
Tag name: statement
case constant expression: statement
default: Statement
Description: The case statement and default statement only appear in the switch statement.
Note that the expression after the case in the same switch can only appear once
switch(exp) { case 2:; case 1+1:; } //ERROR
Tag name: statement is used for goto, the scope is within the function, cannot span functions, and needs to be guaranteed to be the same The label name inside the function is unique.
Loop statements
There are 4 types of loop statements, namely
while ( expression ) statement do statement while ( expression ) ; for ( expression(opt) ; expression(opt) ; expression(opt) ) statement for ( declaration expression(opt) ; expression(opt) ) statement
Loop statements are used to implement the cyclic flow of the program.
Compound statement
A statement enclosed by brackets {} is called a compound statement. Compound statements should be regarded as a single statement in the program rather than multiple statements. For example,
{ x=y+z; a=b+c; printf(“%d%d”,x,a); }
is a compound statement.
Jump statement
There are 4 types of jump statements, namely
goto tag;##continue;
break ;
return expression (optional) ;
Selection statement
if (expression) statement
if ( expression ) statement else statement
switch ( expression ) statement
c Language Tutorial"
The above is the detailed content of What are the six basic statements in C language?. For more information, please follow other related articles on the PHP Chinese website!