+ 3
Please, Explain it...
#include <stdio.h> int main() { char arr[] = {'A','B','C','D'}; char *p = arr; *p++; printf("%c %c",*++p,--*p); return 0; } //Output is : C A // How ?
6 Answers
+ 5
I understand it as below :
https://code.sololearn.com/cVvhS38haZMn/#c
+ 5
*p++ increases the pointer to arr[1] (++ is quicker than *).
I think the arguments in the printf statement are evaluated from right to left (but printed from left to right).
--*p decreases the B at arr[1] to A; arr[1] is given out.
Then the pointer is increased to arr[2] and the letter there given out.
Undefined behaviour, though?
+ 3
HonFu ya may be you are right but still doubtful btw thanks for your help...
+ 2
That kind of riddles are made up with the aim to confuse us, so don't worry about it. đ
+ 2
Prokopios Poulimenos yes i think you are right i compared the same thing in c++ using cout the result was different (output was C B)...
so it is probably the printf in which the variables are update after the statement execution instead of while statement is running...
+ 1
đđ€Ł oh thank you buddy... đđ