我不明白这个C代码中的内容%s
和d%
操作:
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]);
}
Run Code Online (Sandbox Code Playgroud)
我是C语言的新手,我的背景是Java.
%s%d%s%d
符号表示?+
?icc*_*cir 59
printf()函数系列使用%
character作为占位符.%
遇到a 时,printf会读取后面的字符%
以确定要执行的操作:
%s - Take the next argument and print it as a string
%d - Take the next argument and print it as an int
Run Code Online (Sandbox Code Playgroud)
请参阅此维基百科文章以获得精彩图片:printf格式字符串
所述\n
在所述字符串的末尾为换行/回车字符.
小智 7
% 表示法称为格式说明符。例如,%d 告诉 printf() 打印一个整数。%s 打印字符串 (char *) 等。您应该在这里查找:http://google.com/search? q=printf+format+specifiers
不,逗号不用于字符串连接。逗号用于分隔传递给函数的参数。
归档时间: |
|
查看次数: |
329873 次 |
最近记录: |