Open In App

Algorithms Quiz | SP Contest 1 | Question 2

Last Updated : 06 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

What is the output of below program?




#include<bits/stdc++.h>
using namespace std;
  
int main()
{
    int i = 5;
      
    i = i++ * ++i;
      
    cout << i << endl;
      
    return 0;
}


(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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads