C語言的有關(guān)問題
為什么將%c換成%s運行結(jié)果會產(chǎn)生這樣的區(qū)別
#include <stdio.h>
int main()
{??????
??? int height = 185;
??? //補全所有代碼
if(height>=180)???
{???
printf("%c\n","恭喜小明可以參加?;@球隊");??
}???
?return 0;
}
的運行結(jié)果為
hello.c: In function 'main':
hello.c:8:10: warning: format '%c' expects argument of type 'int', but argument 2 has type 'char *' [-Wformat=]
?printf("%c\n","恭喜小明可以參加?;@球隊");
?
?
但是
#include <stdio.h>
int main()
{??????
??? int height = 185;
??? //補全所有代碼
if(height>=180)???
{???
printf("%s\n","恭喜小明可以參加校籃球隊");??
}???
?return 0;
}
的運行結(jié)果為
恭喜小明可以參加?;@球隊
2018-05-07
%s?字符串?
%c?單個字符
單個字符用' '括起來
字符串用" ",
并且%c是指單個的字母或者數(shù)字,例如a,1;
其余問度娘
2018-05-07
因為%c格式對應的是單個字符,而%s格式對應的是一行字符串 ? 這里要輸出的是一行字符串 所以用%s 如果用%d則會輸出錯誤 ?希望可以幫到你