-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointers.c
72 lines (58 loc) · 1.88 KB
/
pointers.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
int main()
{
// Character Type
char c = 'A';
char *cp = &c;
printf("Addresses:\n"
"%u = %u = %u = %u,\n"
"%u\n\n",
&c, cp, cp + 0, &cp[0],
&cp);
printf("Values:\n"
"%c = %c = %c = %c\n\n",
c, *cp, *(cp + 0), cp[0]);
// Integer Type
int d = 10;
int *dp = &d;
int **d2p = &dp;
int ***d3p = &d2p;
printf("Addresses:\n"
"%u = %u = %u = %u = %u = %u = %u = %u = %u = %u = %u = %u,\n"
"%u = %u = %u = %u = %u = %u = %u = %u,\n"
"%u = %u = %u = %u,\n"
"%u\n\n",
&d, dp, *d2p, **d3p, dp + 0, *(d2p + 0), **(d3p + 0),
&dp[0], &d2p[0][0], &d3p[0][0][0], d2p[0], d3p[0][0],
&dp, d2p, *d3p, d2p + 0, *(d3p + 0),
&d2p[0], &d3p[0][0], d3p[0],
&d2p, d3p, d3p + 0,
&d3p[0],
&d3p);
printf("Values:\n"
"%d = %d = %d = %d = %d = %d = %d = %d = %d = %d = %d = %d\n\n",
d, *dp, **d2p, ***d3p, *(dp + 0), **(d2p + 0), ***(d3p + 0),
dp[0], d2p[0][0], d3p[0][0][0], *d2p[0], *d3p[0][0]);
// Float Type
float f[3] = {1.2, 3.4, 5.6};
float *fp = f;
printf("Addresses:\n"
"%u = %u = %u = %u = %u = %u = %u,\n"
"%u = %u = %u = %u,\n"
"%u = %u = %u = %u,\n"
"%u\n\n",
&f, &f[0], f, fp, f + 0, fp + 0, &fp[0],
&f[1], f + 1, fp + 1, &fp[1],
&f[2], f + 2, fp + 2, &fp[2],
&fp);
printf("Values:\n"
"%f = %f = %f = %f = %f = %f,\n"
"%f = %f = %f = %f,\n"
"%f = %f = %f = %f",
f[0], *f, *fp, *(f + 0), *(fp + 0), fp[0],
f[1], *(f + 1), *(fp + 1), fp[1],
f[2], *(f + 2), *(fp + 2), fp[2]);
return 0;
}
// References
// 1. https://en.wikipedia.org/wiki/Pointer_(computer_programming)