#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.out
int = 4
short int = 2
long int = 4
char = 1
float = 4
double = 8
long double = 12
unsigned = 4
unsigned int = 4
unsigned short = 2
unsigned long = 4