Here is a little fellow!
Run:
#include<stdio.h>
int main(){
char a[6]=”abcdef”;
printf(“\n a[5] = %c\n”, a[5]);
printf(“\n 5[a] = %c\n”, 5[a]);
return 0;
}
and be amused ! 😉
If you find this code funny due to second printf statement, just like I thought, it should be noted that in C standard,
type a[b] = *(a + b*sizeof(type))
Also sizeof character is 1 byte making this funny thing to happen!!!
Thanks : http://stackoverflow.com/questions/381542/with-c-arrays-why-is-it-the-case-that-a5-5a?rq=1
Leave a Reply