4 Pointers+Dynamic Memory Allocation
4 Pointers+Dynamic Memory Allocation
The address of a variable = the index of the first byte occupied in memory
If an int variable occupies the bytes numbered 1000, 1001, 1002, 1003, the address of the variable is 1000
Pointers - example
*p *q
2000
...
int x or *p or **r
...
char y
...
int* p = 1000
...
char* q = 2000
...
int** r = 3000
...
char* s = 1000 *t
...
char** t = 6000
sp = new struct mystruct; sp->x = 17; sp->b[3] = 14; sp->d = 9.3; printf("%d, %d\n", sp->x, (*sp).x); spp = &sp; printf("%d, %d\n", (*spp)->x, (**spp).x); sppp = &spp; (***sppp).x = 9; printf("%d, %d, %d, %d\n", (***sppp).x, (**sppp)->x, sp->x, (*spp)->x); delete sp; printf("%d, %d, %d, %d\n", (***sppp).x, (**sppp)->x, sp->x, (*spp)->x);