15
Size in memory of elementary types
- #include <stdio.h>
- main() {
- printf("Size in bytes:\n");
- printf("\t char: %d\n", sizeof (char));
- printf("\t short: %d\n", sizeof (short));
- printf("\t int: %d\n", sizeof (int));
- printf("\t long: %d\n", sizeof (long));
- printf("\t long long: %d\n", sizeof (long long));
- printf("\t float: %d\n", sizeof (float));
- printf("\t double: %d\n", sizeof (double));
- printf("\t long double: %d\n", sizeof (long double));
- printf("\t void *: %d\n", sizeof (void *));
- }
$ gcc -o sizeof sizeof.c
$ ./sizeof
Size in bytes:
char: 1
short: 2
int: 4
long: 4
long long: 8
float: 4
double: 8
long double: 12
void *: 4
Comments