C语言数字类型长度

来源:互联网 发布:python输入ctrl c 编辑:程序博客网 时间:2024/05/29 09:11
#include <stdio.h>int main(void){int  a = 'A';short int b ='A';long int c ='A';char d = 'A';float e = 'A';double f = 'A';long double g ='A';unsigned h ='A';unsigned int i ='A';unsigned short j ='A';unsigned long k ='A';printf("int = %d\n",sizeof a);printf("short int = %d\n",sizeof b);printf("long int = %d\n",sizeof c);printf("char = %d\n",sizeof d);printf("float = %d\n",sizeof e);printf("double = %d\n",sizeof f);printf("long double = %d\n",sizeof g);printf("unsigned = %d\n",sizeof h);printf("unsigned int  = %d\n",sizeof i);printf("unsigned short = %d\n",sizeof j);printf("unsigned long = %d\n",sizeof k);return 0;}
结果:

[root@localhost sourcecode]# gcc sizeof.c[root@localhost sourcecode]# ./a.outint = 4short int = 2long int = 4char = 1float = 4double = 8long double = 12unsigned = 4unsigned int  = 4unsigned short = 2unsigned long = 4