Home > Article > Backend Development > What are the input and output statements in C language?
C language input and output statements include: 1. printf(), used to output information to the screen; 2. scanf(), used to receive input from the keyboard and assign the input value to a variable; 3. getchar(), used to receive a character from the keyboard; 4. putchar(), used to output a character to the screen; 5. gets(), used to receive a line of string from the keyboard; 6. puts( ), used to output a line of string to the screen; 7. scanf_s(), which will perform parameter boundary checking when receiving input.
#The operating environment of this article: Windows 10 system, Dell G3 computer.
There are many kinds of input and output statements in C language, the following are commonly used:
printf function: is used to output information to the screen. The format is printf("format string", variable parameter list). Among them, the format string can contain placeholders to represent the variable type and format to be output. For example, "%d" means outputting integers, "%f" means outputting floating point numbers, "%s" means outputting strings, etc.
scanf function: Used to receive input from the keyboard and assign the input value to a variable. The format is scanf("format string", variable parameter list). Similar to the printf function, placeholders in the format string are used to specify the received variable type and format.
getchar function: is used to receive a character from the keyboard. The format is getchar(). It waits for the user to enter a character and returns the ASCII code of the character.
putchar function: is used to output a character to the screen. The format is putchar (character variable or ASCII code). It outputs the given characters to the screen.
gets function: is used to receive a line of string from the keyboard. The format is gets(string variable). It waits for the user to enter a line of string and stores the entered content into the specified string variable.
puts function: is used to output a line of string to the screen. The format is puts (string variable). It outputs the given string to the screen with automatic line wrapping.
scanf_s function: is a new safe version of the scanf function in the C11 standard. It performs parameter boundary checking when receiving input to avoid security issues such as buffer overflows. The format is scanf_s("format string", variable parameter list).
In addition to the above commonly used input and output functions, C language also provides some other input and output functions, such as: fgets function, fputs function, fscanf function, fprintf function, etc., which can perform input and output operations on files. . The usage of these functions is similar to the functions introduced above, except that you need to specify the file pointer parameter to specify the file to be operated on.
It should be noted that the use of input and output functions requires the corresponding header file. For example, the printf and scanf functions need to include the
The above is the detailed content of What are the input and output statements in C language?. For more information, please follow other related articles on the PHP Chinese website!