C++ Programming - References - Discussion

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

Tushar S. said:   8 years ago
x=y=z=2;

y=b;//assign AND z--; means post decrements.

cout<< z-- ;//First display the outpunt z=2 AND after post decrements by z=z-1 or z--;
// after after post decrements value of x,y,z is x=y=z=1;

Mrunali said:   8 years ago
How x,y,z is 2?

Raj said:   7 years ago
enum bix
{
a=1,b,c
// this means : a=1, b=2,c=3//.
};
int main()
{
int x=c; //means x=3;
int &y=x;
int &z=x;
// this means is x=y=z=3;
y=b;
//in this we assign y=2;
// means x=y=z=2 Right now
cout<<z--; //post increment,
}

Hence output is 2.

Thank you.

Chanchal said:   7 years ago
Thank you @Raj.

Sukanya said:   6 years ago
Enum used a=1, so next variables automatic takes next values,b=2 and c=3.
x=y=z=3;
After y=b assigned so x=y=z=2;
The output will be z-- ,it is a post decrement.
So the output is z=2.
(6)


Post your comments here:

Your comments will be displayed after verification.