web123456

Basics of C language: input, output function

Input and output of C statements and data

Statement C is responsible for issuing instructions to the computer. As long as the statement conforms to the grammar, the computer will execute it smoothly.
C language stipulates that all statements must be ended with a semicolon.
1.functionCall statement
Function call statement is in function callexpressionThen add ";" to form

Its general form is:
Function name (actual parameter name);
2. Expression statements
Expression statements are composed of a semicolon ";" after the expression, and their general format is:
expression;
3. Empty statements
An empty statement is a statement composed of only semicolons" and ", which means that no operation is performed.
In programming, if a certain position needs a statement syntactically but does not require any operation, an empty statement can be used.
4. Compound statements
A compound statement refers to a group of statements that enclose multiple statements in a pair of braces {}.
A compound statement is a combination of multiple statements in form, but it can be regarded as a simple statement in syntax that can appear anywhere in the program.
For example: {t=a;a=b;b=t;}
Note: Each statement in a compound statement must be a semicolon"; "end, but no semicolon can be added outside the braces"; "
Data input and output
In C language, commonly used input and output functions are:printf() function, scanf() function, putchar() function, getchar() function, puts() function, gets() function, gets() function, etc.
The scanf() function and the printf() function are called format input/output functions;
getchar() and putchar() functions are called character input/output functions;
gets function and puts function are called string input/output functions

The general form of the printf() function call is:
scanf (format control string", output table column);
printf (format control string", output table column);
Format control string: used to specify the output format. Format control string consists of format description characters, escape characters and normal characters
Output list: List each output item, separated by commas "," and requires the format control string and each output item to correspond one by one in quantity.
The function of the printf() function: outputs various types of data to external devices of the computer. A printf function can be responsible for outputting multiple data
2. Format description characters
%[flag][output minimum width][precision][length] type
Where, the item in square brackets [] is optional
%o format character: output by octal number
%d format character: output in decimal format
%x format character: PresshexadecimalFormat output
%f format character: output by float and double decimal, and after the decimal point, six digits are retained by default
%c format character: used to output a single character, and can only output one character
%s format: used to output strings