Thursday, October 13, 2016

C (programming language): Sizeof Data Types

Command:

$ cat testsizeof.c


Result:

#include<stdio.h>
int main(){
char str[32];
int ints[16];
long double lds[8];

printf("%lu\n", sizeof(void));
printf("%lu\n", sizeof(char));
printf("%lu\n", sizeof(unsigned char));
printf("%lu\n", sizeof(signed char));
printf("%lu\n", sizeof(short));
printf("%lu\n", sizeof(unsigned short));
printf("%lu\n", sizeof(int));
printf("%lu\n", sizeof(unsigned int));
printf("%lu\n", sizeof(long));
printf("%lu\n", sizeof(unsigned long));
printf("%lu\n", sizeof(float));
printf("%lu\n", sizeof(double));
printf("%lu\n", sizeof(long double));
printf("%lu\n", sizeof(str));
printf("%lu\n", sizeof(ints));
printf("%lu\n", sizeof(lds));

return 0;
}


Command:

$ gcc testsizeof.c 
$ ./a.out 


Result:

1
1
1
1
2
2
4
4
8
8
4
8
16
32
64
128