-
Notifications
You must be signed in to change notification settings - Fork 3
/
sizeof.c
58 lines (55 loc) · 1.24 KB
/
sizeof.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
typedef struct {
char a; //1
int c; //4
// padding 3
int d; //4
int e; //4
int f; //4
// padding 4
double b;//8
}S;
typedef struct
{
short s; /* 2 bytes */
// padding 2
int i; /* 4 bytes */
// padding 3
char c; /* 1 byte */
}X;
typedef struct
{
int i; /* 4 bytes */
char c; /* 1 byte */
short s; /* 2 bytes */
/* 1 padding byte */
}Y;
typedef struct {
char a[3]; //3
short int b; //2
// padding 3
long int c; //8
// padding 5
char d[3]; //3
}Z;
typedef struct {
int a;//4
int b;//4
double c;//8
}A;
int main() {
printf("size of int : %ld\n", sizeof(int));
printf("size of long int : %ld\n", sizeof(long int));
printf("size of int[3] : %ld\n", sizeof(int [3]));
printf("size of char : %ld\n", sizeof(char));
printf("size of char[3] : %ld\n", sizeof(char [3]));
printf("size of float : %ld\n", sizeof(float));
printf("size of double : %ld\n", sizeof(double));
printf("size of int* : %ld\n", sizeof(int *));
printf("size of char* : %ld\n", sizeof(char *));
printf("size of double* : %ld\n", sizeof(double *));
printf("%ld\n", sizeof(A));
printf("%ld\n", sizeof(S));
printf("%ld\n", sizeof(Y));
printf("%ld\n", sizeof(Z));
}