Home >Backend Development >C++ >How to use scanf and printf in c++
The scanf and printf functions in C are used to read data from standard input and write data to standard output. scanf usage: int scanf(format, ...), where format is the data format to be read, ... is the variable address to be read; printf usage: int printf(format, ...), where format is The data format to be written,... is the variable to be written.
Usage of scanf and printf in C
scanf and printf are two commonly used standard input/output functions in C. They are used to read data from standard input and write data to standard output respectively.
scanf
Usage:
<code class="cpp">int scanf(const char *format, ...);</code>
Among them:
format
: Specifies the format string of the data to be read. ...
: The address of the variable to be read. Format specifier:
Example:
<code class="cpp">int age; char name[50]; scanf("%d %s", &age, name);</code>
printf
Usage:
<code class="cpp">int printf(const char *format, ...);</code>Where:
: Specifies the format string of the data to be written.
: Variable to be written.
Format specifier:
<code class="cpp">int age = 25;
printf("姓名:%s,年龄:%d\n", name, age);</code>
The above is the detailed content of How to use scanf and printf in c++. For more information, please follow other related articles on the PHP Chinese website!