0

So the code looks like this (you can access this fiddle here (Click me):

#include <stdio.h>

int main()
{
    int a[5] = { 6, 2, 7, 3, 5 };

    for (int i = 0; i < 5; i++){
        printf("%d ", i[a]);
    }

    printf("\n");

    for (int i = 0; i < 5; i++){
        printf("%d ", a[i]);
    }

    return 0;
}

And this is the output:

6 2 7 3 5
6 2 7 3 5

Apparently, he made a mistake when indexing the array, and inverted the index variable with the array itself. What he found out is that it still prints the same values. This might be a silly question, but again, I don't know much about these types of cases, and this itches me to find out why it's happening what's happening here.

Thanks

0

1 Answer 1

3

x[y] is equivalent to *(x + y) which is equivalent to *(y + x) which is equivalent to y[x].

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.