C
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
#include <stdio.h>
int main() {
// In C, I declare an array of integers
int arr[4] = {3,6,1,2};
// and if then I assign the address of this (the starting element) to another integer pointer
int *p = arr;
// Then I dereference the pointer and increment it as I wish to traverse the array.
printf("%d\n",*p++); //prints out first element and then moves the pointer forward 1 address in memory.
printf("%d\n",*p); //prints out second element
// But then I print out the address in memory of p and arr
printf("%p\n%p\n",p,arr);
// I see that the difference is 4, because integers are stored in 4 bytes
// However, when I subtract the two addresses
printf("%ld\n",p-arr);
// The difference is 1, not 4.
// You could explain this by saying that the 1 itself has 4 bytes,
// so when I am doing
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run