#include <stdio.h> int main() { int a=1; printf ("%d%d%d",a,++a,a++); return 0; } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

#include <stdio.h> int main() { int a=1; printf ("%d%d%d",a,++a,a++); return 0; }

Can any one help me to solve doubt ? "Why it give 331 as output ?"

6th Apr 2022, 4:42 PM
Janvi Desai
3 Answers
+ 2
it have sequence point issue. Sequence of this types execution is Undefined by standards. So Depends on compiler implementation. Means output is may different in different compilers..
6th Apr 2022, 6:29 PM
Jayakrishna 🇮🇳
+ 2
It's not a safe to write increment and decrement calculation and try to avoid your code with such types of calculation becz different different compiler will calculate it differently and compiler will confuse here if u will evaluate multiple increment decrement statements expression try same code in cpp and java u will get different output too
6th Apr 2022, 6:57 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
read this, it's a problem related with the associativity of printf https://www.geeksforgeeks.org/execution-of-printf-with-plusplus-operators-in-c/
6th Apr 2022, 5:18 PM
NonStop CODING
NonStop CODING - avatar