Home  >  Article  >  Backend Development  >  What are the six basic statements in C language?

What are the six basic statements in C language?

hzc
hzcOriginal
2020-07-04 15:04:016015browse

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.

What are the six basic statements in C language?

#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) ;

Jump statement controls program jump Execute at another location.

Selection statement

There are three types of selection statements, namely

if (expression) statement

if ( expression ) statement else statement

switch ( expression ) statement

Recommended tutorial: "

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn