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;
}
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;
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.
{
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.
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers