C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 2)
2.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int main()
{
    int x = 80; 
    int &y = x;
    x++;
    cout << x << " " << --y;
    return 0;
}
The program will print the output 80 80.
The program will print the output 81 80.
The program will print the output 81 81.
It will result in a compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
17 comments Page 2 of 2.

Demented_hedgehog said:   10 years ago
There's no sequence point for the << operator so the order of evaluation is unspecified.

Hatos said:   8 years ago
My output is;

81 80

Code::Blocks
Release 17.12 rev 11256
g++.exe (GCC) 7.2.0
std = c++1z
(1)

Sid said:   4 years ago
In C++17 answer is 81 80 and in C++ 14 ans is 80 80.
(4)

Anant Supekar said:   5 years ago
The correct answer will be 81 80.
(3)

Bhavesh Garg said:   2 years ago
The Correct Answer is (B) 81 80.
(15)

Anusha said:   5 years ago
The correct answer is 81 80.
(4)

Serg said:   7 years ago
Of course, it is 81 80.


Post your comments here:

Your comments will be displayed after verification.