2

I just know this trick.

In C++:

#include <iostream>
using namespace std;

int main() {
    int i[3]={5,7,11};
    cout << 2[i];
    return 0;
}

In C:

#include <stdio.h>
int main(void) 
{  
    int i[3]={5,7,11};
    printf("%d", 2[i]);
    return 0; 
}

yes, these are allowed, both output are 11.

why i[2] can be expressed as 2[i]?

athos
  • 6,120
  • 5
  • 51
  • 95

1 Answers1

11
a[i] = i[a]

*(a+i) = *(i+a)

Hence both are same and is valid.

Gopi
  • 19,784
  • 4
  • 24
  • 36