汇集网友智慧,解决技术难题
C语言 print printf printf函数
赞0
评论
2025-03-16
2025-03-15
2025-03-12
2025-03-11
点击图片添加到编辑器内容中
点击文件名将附件添加到文章中
提交
tyw
318个答案
天意无罪
287个答案
xch
236个答案
jjjyufan
206个答案
coody
201个答案
LcwSwust
170个答案
chunyang
135个答案
地瓜patch
126个答案
赞0
char fmt[64];
snprintf(fmt, sizeof(fmt), "a=%d, b=%d\n", a, b);
printf(fmt); // 输出 "a=10, b=20\n"
评论
2025-03-16
赞0
评论
2025-03-15
赞0
对于字符串,可以指定最大输出的字符数。例如,printf("%.5s", "Hello, World!")将输出"Hello"。
评论
2025-03-15
赞0
评论
2025-03-15
赞0
printf("%s\n%3s\n", "a", "b"); // 输出:
// a
// b
评论
2025-03-15
赞0
int main() {
int num = 123;
printf("%#x\n", num); // 输出:0x7b
printf("%06d\n", num); // 输出:000123
printf("%-6d\n", num); // 输出:123
printf("%+d\n", num); // 输出:+123
printf("% d\n", num); // 输出: 123
return 0;
}
评论
2025-03-15
赞0
评论
2025-03-12
赞0
评论
2025-03-12
赞0
printf("%*d\n", 5, 123); // 输出 " 123"
// 动态精度控制(精度由第二个参数决定)
printf("%.2f\n", 3.14159); // 输出 "3.14"
printf("%.*f\n", 2, 3.14159); // 输出 "3.14"
评论
2025-03-11
您需要登录后才可以回复 登录 | 注册