#include <stdio.h>
int main(void)
{
char c[]="GATECSIT2017";
char *p=c;
printf("%s", c+2[p]-6[p]-1);
return 0;
}
What do 2[p] and 6[p] mean?
Please provide a detailed explanation.
Output: 17
#include <stdio.h>
int main(void)
{
char c[]="GATECSIT2017";
char *p=c;
printf("%s", c+2[p]-6[p]-1);
return 0;
}
What do 2[p] and 6[p] mean?
Please provide a detailed explanation.
Output: 17
For any valid pointer or array p and index i, the expression p[i] is equal to *(p + i). And due to the commutative property of addition *(p + i) is equal to *(i + p) which is then equal to i[p].
In short, 2[p] is the same as p[2].
What do
2[p]and6[p]mean?
2[p] is equivalent to p[2] and 6[p] is equivalent to p[6].