Jee*_*tel 11 c sizeof char literals
可能重复:
为什么C字符文字的内部而不是字符?
#include<stdio.h>
int main(void)
{
char b = 'c';
printf("here size is %zu\n",sizeof('a'));
printf("here size is %zu",sizeof(b));
}
Run Code Online (Sandbox Code Playgroud)
这里输出(见现场演示在这里.)
here size is 4
here size is 1
Run Code Online (Sandbox Code Playgroud)
我不明白为什么sizeof('a')是4?
San*_*raj 10
以下是著名的名句C书- The C programming Language通过Kernighan & Ritchie相对于单引号之间写入字符.
A character written between single quotes represents an integer value equal to the numerical value of the character in the machine's character set.
所以sizeof('a')相当于sizeof(int)