-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathc.structs.sheet
69 lines (51 loc) · 994 Bytes
/
c.structs.sheet
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
59
60
61
62
63
64
65
66
67
68
69
# C Structures
# Named Structure
struct point {
int x;
int y;
};
struct point p = { 5, 10 };
# Named With Several Initialized Points
struct point {
int x;
int y;
} a = { 1, 2 },
b = { 5, 5 },
c = { 2, 4 };
# With Initial Array
struct {
int x;
int y;
} points[] = {
{ 1, 2 },
{ 2, 3 },
};
points[0].x
points[0].y
# With Initial Array '{' and '}' are optional
static struct {
char *string;
char *str;
} months[] = {
"January", "Jan",
"February", "Feb",
"March", "Mar",
};
months[0].string
months[0].str
# Typedef
typedef struct {
int x;
int y;
} Point;
Point p = { 1, 2 };
# Self Referential TypedefR
typedef struct _point_ {
int x;
int y;
struct _point_ *last;
} Point;
Point a = { 1, 2, NULL };
Point b = { 1, 2, &a };
printf("<Point x:%d y:%d>\n", b.last->x, b.last->y);
// => <Point x:1 y:2>