Last Updated :
06 Jan, 2019
What is the output of below program?
#include
using namespace std;
int main()
{
int i = 5;
i = i++ * ++i;
cout << i << endl;
return 0;
}
[/sourcecode]
(A) 35
(B) 30
(C) 53
(D) Undefined( Compiler Specific )
Answer: (D)
Explanation: In this program, i is getting updated more than once in an expression without sequence points. This will cause undefined behavior, i.e., the output of the program will be different for compilers with different architectures. Please refer https://en.cppreference.com/w/cpp/language/ub for details.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...