-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructures.c
46 lines (35 loc) · 1.09 KB
/
structures.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
#include <stdio.h>
struct example
{
char c;
int d;
double lf;
};
int main()
{
struct example obj = {'A', .d = 10};
obj.lf = 1.2;
struct example *objp = &obj;
printf("Addresses:\n"
"%u = %u = %u = %u = %u = %u = %u = %u,\n"
"%u = %u = %u = %u,\n"
"%u = %u = %u = %u,\n"
"%u\n\n",
&obj, objp, objp + 0, &objp[0],
&obj.c, &(objp->c), &((objp + 0)->c), &(objp[0].c),
&obj.d, &(objp->d), &((objp + 0)->d), &(objp[0].d),
&obj.lf, &(objp->lf), &((objp + 0)->lf), &(objp[0].lf),
&objp);
printf("Values:\n"
"%c = %c = %c = %c,\n"
"%d = %d = %d = %d,\n"
"%lf = %lf = %lf = %lf\n\n",
obj.c, objp->c, (objp + 0)->c, objp[0].c,
obj.d, objp->d, (objp + 0)->d, objp[0].d,
obj.lf, objp->lf, (objp + 0)->lf, objp[0].lf);
printf("Sizes:\n%d + %d + %d = %d",
sizeof obj.c, sizeof obj.d, sizeof obj.lf, sizeof obj);
return 0;
}
// References
// 1. https://en.wikipedia.org/wiki/Struct_(C_programming_language)