printf函数可以将值和变量打印显示在控制台窗口中。
#include <stdio.h>
int main() {
int x = 5;
printf("x is %d and 2+3 is %d", x, 2+3);
}
%d限定符显示char,short或int类型的整数。 其他常用的格式限定符如下表所示。
| 限定符 | 输出 |
|---|---|
%d 或 %i |
char, short 或 int |
%c |
字符 |
%s |
字符串 |
%f |
float或double |
%Lf |
长精度 |
%ld |
长整型 |
%lld |
超长整型 |
%u |
unsigned char,short或int |
%lu |
unsigned long int |
%llu |
unsigned long long int |
%p |
指针地址 |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/266397.html