Strange pointers

Strange pointers

Sergey Abbakumov

You probably know that the compiler expands the following code:

const int array[] = {0, 1, 2};
const int val = array[1];


as

const int array[] = {0, 1, 2};
const int val = *(array + 1);


This fact implies one feature: you can write the same code like this:

const int array[] = {0, 1, 2};
const int val = 1[array];


and everything works. The fact is that in C/C++ this construction still expands as:

const int array[] = {0, 1, 2};
const int val = *(1 + array);


Telegram channel: https://t.me/sea_plus_plus

Report Page