This question was asked in a recent exam where the candidate had to find the output for the following code:
#include<stdio.h>
#include<string.h>
int main()
{
char * c = "GATECSIT2017";
char *p = c;
printf("%d", (int)strlen(c+2[p]-6[p]-1));
return 0;
}
I started coding in C++ , so I wasn't an expert in C-Strings. After messing around with code, I understood how it worked, but one thing wasn't clear to me, which was this way of accessing a char from the char* string.
My question is, how 2[p]
gets the character at index 2?
Does it resolve into *(p+2)
or is there something else going on? Also, is there any documentation or any article that could explain this behavior?