1 min read

Funny C code

Here is something funny about C langage :)
Watch carefuly this function below and try to guess what will this program print to the console.


#include < stdio.h >

int main(void)
{
    int p[] = {0, 1, 2, 3, 4, 5, 6, 7};
    int i=3;

    printf("i[%d]=%d\n", i, i[p]);
    return 0;
}

Is this code correct ? If the answer is yes, then what doest printf print ?
Well … the answer is easy …


i[p] = *(i + p) = *(p + i) = p[i] = 3;