#include <stdio.h>
int main(int argc, char *argv[]){
int *ia[5]={0,1,2,3,4};
iap=ia;
printf("ia[3]:%d\n",3[ia]);
return 0;
}
Why is that line working in C?
#include <stdio.h>
int main(int argc, char *argv[]){
int *ia[5]={0,1,2,3,4};
iap=ia;
printf("ia[3]:%d\n",3[ia]);
return 0;
}
Why is that line working in C?
The amazing world of C pointer arithmetic:
ia[3]
is computed as *(ia + 3)
, which is the same as *(3 + ia)
or 3[ia]
.
You can also write 1[ia+2]
, or 3[ia-+!ia]
, or even 2[1+ia, ia+1]
...
None of these should appear in regular code unless you are trying to obfuscate and confuse the casual reader/maintainer/code reviewer.