–1 votes –1 votes int main(){ int a =5; printf("%d %d %d %d %d ",a++,a--,++a,--a,a); } Output is "4 5 5 5 5". How???? Programming in C non-gate + – atul_21 asked Jun 30, 2017 atul_21 3.7k views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply akankshadewangan24 commented Jun 30, 2017 i reshown by Arjun Jun 30, 2017 reply Follow Share this is compiler dependent right? –1 votes –1 votes sarbesh commented Jun 30, 2017 reply Follow Share I think 45545 be answer –1 votes –1 votes Arjun commented Jun 30, 2017 reply Follow Share For all these types of questions which are anyway not relevant for GATE https://gateoverflow.in/62411/undefined-behaviour-in-c 1 votes 1 votes akankshadewangan24 commented Jun 30, 2017 reply Follow Share thanks for clearing doubt sir 1 votes 1 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes 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.". Deepak Kumar 12 answered Jun 30, 2017 • selected Jun 30, 2017 by Arjun Deepak Kumar 12 comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes According to turboo c++ compile save it as .C extension the Answer is 45545 rakesh kumar meena answered Jul 3, 2017 rakesh kumar meena comment Share Follow See all 0 reply Please log in or register to add a comment.