对于 sizeof(char)的一些零碎······

先看一段简单的c程序

  

 1 #include<stdio.h>
 2 
 3 int main(void){
 4     
 5     char c ='a';
 6     
 7     printf("the size of 'a' is %d
",sizeof('a'));
 8     printf("the size of  c  is %d
",sizeof(c));
 9     printf("the size of  char is %d
",sizeof(char));
10     
11     return 0;
12 }

ok,结果如下图:

  

为啥子····sizeof(‘a’)是4个直接涅???

  因为字符实际上是以 数值存储的。所以也可以用数值编码来赋值····

  即  

char c = 97

假定有下列声明:

  char sign = '$'; sign 癿存偹需要多少字节? '$' 呢? "$" 呢?

  答: 字符常量sign用一个字节, . 但是字符常量是被存储在一个 int中,也就是说‘$’通常使用2个或者4个字节;

    但是,实际上,只使用一个直接存储'$'编码。字符串 "$" 使用两个字节, 一个用来保存 '$' ,一个字节用来保存 
           '' .
          

原文地址:https://www.cnblogs.com/kalo1111/p/3257463.html