Function and Classification of C Statements
01
Function of C Statements
A function consists of a declaration part and an execution part. The execution part is composed of statements, which issue operation instructions to the computer system, requesting the execution of corresponding operations. A C statement generates several machine instructions after compilation. The declaration part is not a statement; it does not produce machine instructions but only declares relevant data.
✦
✦
02
Classification of C Statements
1. Control Statements. Used to complete certain control functions, divided into nine categories, as follows:
① if( )~else conditional statement ② for( )~ loop statement ③ while( )~ loop statement ④ do~while( ) loop statement ⑤ continue ends the current loop statement ⑥ break interrupts the execution of switch loop statement ⑦ switch multi-branch selection statement ⑧ goto jump statement ⑨ return returns from function statement
2. Function call statements. Composed of a function call plus a semicolon, for example:
printf(“This is a C statement”);
3. Expression statements. Composed of an expression plus a semicolon, for example:
a=3;
The most typical assignment statement is formed by an assignment expression, for example:
i=i+1;
4. Empty statement
;
Only a semicolon, it can be used as a flow control point and can also serve as a loop structure in loop statements.
5. Compound statements. Some statements and declarations can be enclosed in { } to form a compound statement, also known as a statement block. For example:

✦
✦
Input and Output of Data
01
Concepts Related to Data Input and Output
(1) Input and output are considered from the perspective of the computer host. Outputting data from the computer to output devices (such as monitors, printers, etc.) is called output, while inputting from input devices (such as keyboards, CDs, scanners, etc.) is called input.
(2) The C language itself does not provide input and output statements; input and output operations are implemented by functions in the C standard library. The C standard library provides some input and output functions for the keyboard, such as the printf function and the scanf function. Readers should not mistakenly believe that they are “input and output statements” provided by the C language. printf and scanf are not keywords in C language; they are merely the names of library functions. In fact, one can write another input function and an output function to achieve input and output functionality without using the names printf and scanf.
(3) In the program file, preprocessor directive #include is used to include relevant header files in this program. For example: #include<stdio.h>
✦
✦
02
Using printf Function to Output Data
1. General format of printf function
printf(format control, output list)
For example: printf(“%d, %c\n”, i, c)
(1) “Format control” is a string enclosed in double quotes, referred to as the format control string, or simply format string. It includes two types of information:
① Format declaration. The format declaration consists of a “%” and format characters, such as %d, %f, etc. Its role is to convert the output data to the specified format before outputting. The format declaration always starts with the “%” character.
② Ordinary characters. Ordinary characters are those that need to be output as is. For example, the comma, space, and newline character inside the double quotes in the above printf function, and it can also include other characters.
(2) Output list. Some data that the program needs to output; they can be constants, variables, or expressions.

2. printf format conversion characters

✦
✦
03
Using scanf Function to Input Data
1. General format of scanf function
scanf(format control, address list)
2. scanf format escape characters

3. Issues to note when using scanf function
(1) The format after scanf function should be the variable’s address, not the variable name.
(2) If there are other characters besides the format declaration in the format control string, the same characters should be input in the corresponding positions when inputting data.
✦
✦
04
Character Input and Output Functions
1. Use putchar function to output a character
The general form of putchar function is:
putchar(c)
Example: Output the three characters BOY

2. Use getchar function to input a character
The general form of getchar function is:
getchar()
Example: Input the three characters BOY from the keyboard and output them to the screen.

*Statement:This article is organized from the internet, copyright belongs to the original author. If the source information is incorrect or infringes rights, please contact us for deletion or authorization matters.
