Home > Backend Development > C++ > body text

The meaning of scanf in c language

下次还敢
Release: 2024-05-02 19:54:15
Original
1159 people have browsed it

The scanf function is an input function in C language used to read formatted data from standard input. Usage is as follows: Specify the format of the input data (using a format string). Provide the variable address (using the & operator). Reads data from standard input according to a formatted string and stores it in the specified variable.

The meaning of scanf in c language

The meaning of scanf function in C language

The scanf function is a standard input function in C language. Use Used to read formatted data from standard input (usually the keyboard) and store it in a specified memory location.

Usage:

scanf("formatted string", & variable list);

Among them:

  • Format string: Specify the format of the input data, for example, "%d" represents an integer and "%f" represents a floating point number.
  • Variable list: Variable addresses that store input data in sequence.

Example:

<code class="c">int age;
float weight;
scanf("%d %f", &age, &weight);</code>
Copy after login

In this example, the scanf function reads two data from the standard input. The first data is an integer and is stored in age variable, the second data is a floating point number and is stored in the weight variable.

Format characters:

Format characters Data type
%d Integer
%f Floating point number
%c Character
%s String

Note Matters:

  • #scanf function requires that the format of the input data is consistent with the format string, otherwise an error will occur.
  • When using the scanf function, you must use the & operator to obtain the variable address.
  • The scanf function skips leading whitespace characters.

The above is the detailed content of The meaning of scanf in c language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template