-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer_array_test.c
More file actions
47 lines (37 loc) · 904 Bytes
/
pointer_array_test.c
File metadata and controls
47 lines (37 loc) · 904 Bytes
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
#include <stdio.h>
static void pointer_array();
static void two_dimensional_array();
int main() {
pointer_array();
two_dimensional_array();
return 0;
}
static void pointer_array() {
char *persons[3] = {
"John Doe",
"Jane Doe",
"Foo Bar"
};
char *person_ptr;
for (int i=0; i < 3; i++) {
person_ptr = *(persons + i);
printf("Address of person %u = %p\n", i, person_ptr);
printf("Person %u = %s\n", i, person_ptr);
}
}
static void two_dimensional_array() {
char data[3][11] = {
"0123456789",
"abcde",
"fghij"
};
// Using pointer syntax;
char *item_ptr;
for (int i=0; i < 3; i++) {
item_ptr = *(data + i);
printf("data %u = %s\n", i, item_ptr);
}
// Using array syntax;
for (int i = 0; i < 3; i++)
printf("data %u = %s\n", i, data[i]);
}