#include<stdio.h>
main()
{
char s[]="man";
int i=0;
printf("%c%c\n",s[i],i[s]);
}
o/p: m m
*Both s[i] and i[s] prints 'm' and 'm'.
*However s[i]=m, that is acceptable,but how i[s]=m ??
*Can any one explain me about this please.
#include<stdio.h>
main()
{
char s[]="man";
int i=0;
printf("%c%c\n",s[i],i[s]);
}
o/p: m m
*Both s[i] and i[s] prints 'm' and 'm'.
*However s[i]=m, that is acceptable,but how i[s]=m ??
*Can any one explain me about this please.
It's because s[i]
is equivalent to *(s + i)
, and due to the commutative properties of addition, *(s + i)
is equal to *(i + s)
which leads to i[s]
being valid.