4,522 views
–1 –1 vote
int main(){

int a =5;
printf("%d %d %d %d %d ",a++,a--,++a,--a,a);

}

Output is "4 5 5 5 5". How????

2 Answers

Best answer
1 1 vote
It is compiler dependent in C.Order of evaluation of arguments of a function is not guaranteed  in C and C++.The order of evaluation of function arguments is unspecified because allowing the compiler to re-order the evaluation of the operands adds more room for optimization.

Bjarne Stroustrup also says it explicitly in "The C++ Programming Language" 3rd edition section 6.2.2, with some reasoning:-

"Better code can be generated in the absence of restrictions on expression evaluation order.".
• selected by
Position:
Show:

Related questions

0 0 votes
1 1 answer
732
732 views
gatecse asked Dec 9, 2020
732 views
Match the following:$$\begin{array}{|l|l|l|l|} \hline (1) \text{Waterfall model} & (a) \text{Specifications can be developed} \\& \text{incrementally} \\\hline (2) \tex...
8 8 votes
1 answers 1 answer
7.4k
7.4k views
sh!va asked May 7, 2017
7,438 views
Estimation at software development effort for organic software in basic COCOMO is:E = 2.0 (KLOC) 1.05 PME = 3.4 (KLOC) 1.06 PME = 2.4 (KLOC) 1.05 PME = 2.4 (KLOC) 1.07...
0 0 votes
2 answers 2 answers
1.6k
1.6k views
logan1x asked May 19, 2019
1,561 views
A default catch block catches,[A]. all thrown objects[B]. no thrown objects[C]. any thrown object that has not been caught by an earlier catch block[D]. all thrown object...
0 0 votes
1 1 answer
756
756 views
go_editor asked Sep 18, 2018
756 views
What will be the output of the following C program? If you think it will give a runtime error, you need to mention it. In either case, your answer must include proper jus...