+ 9
Why this code prints CA ?
char a[]={'A', 'B', 'C', 'D'}; char *ppp = &a[0]; *ppp++; printf("%c%c", *++ppp, --*ppp);
8 Respuestas
+ 4
I didn't understand how it's work at this line:
printf("%c%c", *++ppp, --*ppp); //
As I see *++ppp should change the point to the next point a[2] and return its value.
--*ppp should get current point and decrease its value. Why the previous value is changing a[1] and not the current a[2]??? If we add printf of *ppp to the end it will return a[2].
+ 4
Earl Grey, you're absolutely right. It applies right to left rule.
+ 3
char a[]={'A', 'B', 'C', 'D'};
char *ppp = &a[0];
*ppp++; //This changes the pointer to point to a[1]
printf("%c%c", *++ppp, --*ppp); //equal precedence so right to left rule
+ 3
Let start from the first *ppp++; which is before the printf statement which will take it to 'B', and in the printf moving a step ahead is 'C' and taking a step backward is 'A'. I hope you get that Mihai C
+ 3
After assigning the 0th Element the pointer having value of a[0]... Then you increment the pointer .... That will get the 1st Element and after that.... In printf, if you increment it will go 2nd position and if you decrement it will go 0th position.... But actually the pointer in 1st position.... That's all..