-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointers_extra.c
56 lines (47 loc) · 1.43 KB
/
pointers_extra.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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
//uint32_t * nums = (uint32_t *) 0x0001; // 0x0001 | 01 00 00 00, 02 00 00 00, 03 00 00 00
// nums = an integer of 0x0001 - not a legal address
// or
//uint32_t nums[] = { 1, 2, 3 };
// nums = an integer pointer generated by the compiler linker; points to somwhere in the data section of the executable
// pointer is legal
//0x0001 | 01 00 00 00, 02 00 00 00, 03 00 00 00
uint32_t *nums = (uint32_t *) 0x0001;
printf("%i \n", *nums); // = 1
printf("%i \n", nums[0]); // = 1
printf("%i \n", nums[1]); // = 2
printf("%i \n", nums[2]); // = 2
printf("%p \n", nums); // 0x0001
printf("%p \n", &nums[0]); // 0x0001
printf("%p \n", &nums[1]); // 0x0001 + sizeof(uint32_t)
printf("%p \n", &nums[2]); // 0x0001 + sizeof(uint32_t) + sizeof(uint32_t)
int a = 2;
int *p = &a;
printf("%d\n", p[10]);
//printf("%d", sizeof(int));
int *array_int;
array_int = malloc(sizeof(int) * 10);
char *string = "first string";
char **str;
str = malloc(sizeof {})
int index = 0;
while (string[index]) {
printf("%c\n", string[index]);
index++;
}
index = 0;
while (index < 10) {
array_int[index] = index;
index++;
}
int a = 0;
int *p = &a;
printf("%p\n", p);
printf("%p\n", &p[10]);
printf("%p\n", p + 10);
}