Pointer Subscripting
In pointer, we can also do subscripting like pointer[i]
, for example we can do something like:
#include <stdio.h>
#include <stdlib.h>
int main() {
int* pointer;
printf("pointer: %p, pointer[1]: %p\n", pointer, &pointer[1]);
}
In here, pointer[1]
will be the next 4 bytes of pointer.
pointer: 0x101049bd0, pointer[1]: 0x101049bd4
[!note]
When doingpointer[1]
, we're refering to rvalue ofpointer
, which is going to be anint
. Sincepointer[1]
is the same as*(pointer + 1)
hence it's going to be the values of it.