单引号与C或C双引号++ [英] Single quotes vs. double quotes in C or C++
问题描述
当我应该使用单引号和C或C ++编程双引号?
When should I use single quotes and double quotes in C or C++ programming?
推荐答案
在C和C ++中单引号识别单个字符,而双引号创建一个字符串。 '一'是一个单一的字符文字,而一是一个字符串常量,其中包含了'a'和一个空结束(这是一个2字符数组)。
In C and in C++ single quotes identify a single character, while double quotes create a string literal. 'a' is a single a character literal, while "a" is a string literal containing an 'a' and a null terminator (that is a 2 char array).
请注意,在C,字符文字的类型是 INT
,而不是字符
,即 sizeof的'A'
是一个架构,其中的int是32位4(和CHAR_BIT是8),而的sizeof(char)的
1无处不在。
Note that in C, the type of a character literal is int
, and not char
, that is sizeof 'a'
is 4 in an architecture where ints are 32bit (and CHAR_BIT is 8), while sizeof(char)
is 1 everywhere.
这篇关于单引号与C或C双引号++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!