0

Can someone explain me output of the code?

#include <stdio.h> int main() { char s[12]="SOLOLEARN"; int i = 1; char ch1 = ++i[s]; char ch2 = i++[s]; printf("%c",ch1); printf("\t%c",ch2); return 0; } // Output :- P P

28th May 2020, 5:33 PM
Ajay Kumar Maurya
Ajay Kumar Maurya - avatar
1 Antwort
0
Line ch1: Is implicitly ++(i[s]) i[s] is the char 1 of s (the first O) As pre-incr. is used, this char is at first incremented (to P) and then stored into ch1 (ch1=='P') Note: s is now "SPLOLEARN" Line ch2: Is implicitly (i++)[s] As post-incr. is used, i[s] is stored into ch2 (ch2=='P') Afterwards i is incremented. Does that answer your question?
28th May 2020, 7:06 PM
Michi
Michi - avatar