printf函数可以将值和变量打印显示在控制台窗口中。

#include <stdio.h>

int main() {
  int x = 5;
  printf("x is %d and 2+3 is %d", x, 2+3);
}

%d限定符显示charshortint类型的整数。 其他常用的格式限定符如下表所示。

限定符 输出
%d%i char, shortint
%c 字符
%s 字符串
%f floatdouble
%Lf 长精度
%ld 长整型
%lld 超长整型
%u unsigned charshortint
%lu unsigned long int
%llu unsigned long long int
%p 指针地址