#include<stdio.h>
int main() {
char *s="Manikant";
int i=0;
printf("%s\n",s+s[2]-s[4]); // Line-1
printf("%d\n",printf("GATE-2017")); //Line-2
printf("%c%d\n",s[i++],i); //Line-3
}
O/P
ikant
GATE-20179
M1 // undefined [sequence point error]
s+s[2]-s[4] evalutes to s+3
printf("GATE-2017") , here 9 characters are printed by inside printf(). So inside printf() returns 9. => first printf prints 9 after GATE-2017
S[i++] expression evalutes to S[0] because of post increment.
Line3:
If an object is written to within a full expression, any and all accesses to it within the same expression must be directly involved in the computation of the value to be written.
printf("%c%d\n",s[i++],i); Here, we are accesing $i$ in the second argument of printf() but, it has nothing to do with the storing of $i$,which is a side effect of s[i++]. => causes undefined behaviour. Link