The scanf function reads formatted data from standard input and stores it in the specified variable. Usage: 1. Define the variable to store the data; 2. Specify the format string, including the data type indicator; 3. Pass the variable address as a parameter to scanf in sequence; 4. Call scanf to read the data.
scanf function
scanf is a function in the standard input/output library in C, used to read from the standard Read formatted data from the input.
Function:
scanf reads data from standard input (usually the keyboard) and stores it in the provided variable. It reads data according to a specified format string that defines the expected data type and format of each variable.
Syntax:
<code class="cpp">int scanf(const char *format, ...);</code>
Among them:
format
: Pointer to the format string, specify the The data type and format to be read. ...
: Optional variable parameter list, specifying the address of the variable to store the read data. Usage:
The steps to use scanf to read data are as follows:
Specifies a format string where:
%
: Indicates the start of the conversion specification. d
, f
, s
): Specifies the data type to be read. *
, &
): modify the conversion specification. Example:
<code class="cpp">int age; float salary; char name[50]; scanf("%d %f %s", &age, &salary, name);</code>
The above code reads an integer (age), a floating point number (salary) and a string (name) from the standard input ).
Note:
*
and &
after reading data. The above is the detailed content of What does scanf in c++ mean?. For more information, please follow other related articles on the PHP Chinese website!