C中单引号和双引号之间的差异 [英] Differences between single-quotes and double-quotes in C
问题描述
最近我已经看到,如果将 printf
与'foo'一起使用,则会收到警告。
Recentely I have seen that if I use printf
with 'foo' I get a warning.
printf('numero');
警告:字符常量的类型太长[默认启用]
警告:传递'printf'的参数1将使整数
的指针不进行强制转换。 /usr/include/stdio.h:362:12:注意:预期为'const
char * restrict ',但参数的类型为'int'extern int printf
(const char * __ restrict __format,...);警告:格式化不是字符串
文字,并且没有格式化参数[-Wformat-security]
warning: character constant too long for its type [enabled by default] warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast. /usr/include/stdio.h:362:12: note: expected ‘const char * restrict’ but argument is of type ‘int’ extern int printf (const char *__restrict __format, ...); warning: format not a string literal and no format arguments [-Wformat-security]
当我使用
我没有收到任何警告 printf( numero);
And when I use ""
I don't get any warnings printf("numero");
那么,''
和
有什么区别?
推荐答案
在 c ,''
用于字符常量,
用于字符串,与 python 的问题,两者可以互换使用。
In c, ''
is used for character constants and ""
for string, unlike python where both can be used interchangeably.
这篇关于C中单引号和双引号之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!