Home  >  Article  >  Backend Development  >  ~What does scanf mean in C language?

~What does scanf mean in C language?

下次还敢
下次还敢Original
2024-04-13 18:12:41807browse

scanf is a C language standard library function used to read data from standard input. The function prototype is int scanf(const char *format, ...), where format specifies the type and format of the data to be read, and ... is a variable number of parameters pointing to the variable address of the data to be read. Returns the number of input items successfully read, or EOF (-1) if no input could be read.

~What does scanf mean in C language?

scanf Meaning in C language

scanf Is a standard library function in the C programming language for reading data from standard input.

Function prototype:

<code class="c">int scanf(const char *format, ...);</code>

Parameters:

  • format: a format character String, specifying the type and format of the data to be read.
  • ...: A variable number of parameters, pointing to the address of the variable to read the data.

Return value:

scanf Returns the number of successfully read input items. If no input can be read due to an error or end-of-file reached, EOF (-1) is returned.

Usage:

scanf Use a format string to instruct it to read data from the input stream. The format string specifies the type and format of the data to be read. Commonly used format specifiers include:

  • %d - integer
  • %f - floating point number
  • %c - character
  • %s - string

Example:

<code class="c">int age;
char name[20];

scanf("%d %s", &age, name);</code>

in this example , scanf will read an integer from standard input and store it in the age variable, and then read a string and store it in name in the array.

The above is the detailed content of ~What does scanf mean 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