Article directory
1 output function printf
The format output function commonly used in C language is printf. 使用printf时,需要声明头文件stdio.h
. The basic format of printf is
printf ("格式控制字符串",输出列表);
The commonly used format specification characters are as follows
format character | meaning |
---|---|
%d | print as a decimal integer |
%o | Output integers in octal, without prefix 0 |
%x | Integer output in hexadecimal |
%u | Output an unsigned integer as a decimal number |
%f | Output according to the floating point number, the default output is 6 bits |
%.nf | Output according to the floating point number, output n decimal places |
%c | output a single character |
%s | output string |
%p | Output pointer (address) value in hexadecimal |
如果在“%”后为“-”,表示输出结果左对齐(在规定输出长度的情况下,默认为右对齐),如果在“%”后为“+”,则输出数值的符号 (正号或负号)。
2 Input function scanf
The format input function commonly used in C language is scanf. The basic format of scanf is
scanf("格式字符串",地址列表);
The address list consists of the address operator "&" and variable names. In addition to scanf, there are getchar, putchar, gets, etc. in C language.