-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples
79 lines (64 loc) · 860 Bytes
/
examples
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
70
71
72
73
74
75
76
77
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
//arithmetic -- operator precedence
a = 123;
b = a + 321;
c = b / 111;
d = 4 * 9 + 6 / 2;
d = 4 * (9 + 6) / 2;
e = 56;
f = e++;
//struct definition
struct point {
int x;
int y;
}p1;
//struct member access
p1.x = 123;
p1.y = 321;
//struct pointer
struct point *sptr = &p1;
sptr->x = 90;
sptr->y = 10;
g = p1.x;
h = p1.y + g;
//dynamic allocation
sptr = new struct point;
int i;
//while loop + allocation
int* ptr;
i=0;
while(i<4) {
i++;
ptr = new int;
}
//array-like data structure
struct array {
int current;
int length;
int * data;
};
struct array arr;
arr.current = -1;
arr.length = 9;
i = 1;
while(arr.length > i) {
i++;
arr.current++;
arr.data = new int;
}
while(arr.current > 0) {
arr.current--;
arr.data--;
}
while(arr.current < 4) {
arr.current++;
arr.data++;
}
*arr.current = 945;