什么%s和%d个意味着在C语言中的printf? [英] What does %s and %d mean in printf in the C language?
本文介绍了什么%s和%d个意味着在C语言中的printf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白什么%S
和 D%
做这个C code:
I don't understand what the %s
and d%
do in this C code:
for (i=0;i<sizeof(code)/sizeof(char*); i++) {
printf("%s%d%s%d\n", "Length of String ", i, " is ", strlen(code[i]));
str = code[i];
printf("%s%d%s%c\n","The first character in string ", i, " is ", str[0]);
}
我是新的C语言和我的背景是在Java中。
I'm new to the C language and my background is in Java.
- 怎么做
%s的%D%S%ð
符号表示? - 为什么有这么多的人?
- 就是这里用于级联代替
+
? 逗号
- What do the
%s%d%s%d
symbols denote? - Why are there so many of them?
- Is the comma used here for concatenation instead of a
+
?
推荐答案
的printf()系列功能用途%
字符作为占位符。当%
遇到,下面的printf读取字符%
来决定做什么:
The printf() family of functions uses %
character as a placeholder. When a %
is encountered, printf reads the characters following the %
to determine what to do:
%s - Take the next argument and print it as a string
%d - Take the next argument and print it as an int
见一个漂亮的图片此Wikipedia文章:格式化字符串
的 \\ n
在字符串的结尾是一个换行符/回车符。
The \n
at the end of the string is for a newline/carriage-return character.
这篇关于什么%s和%d个意味着在C语言中的printf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文