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 1 of 2.
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)
Chanchal said:
7 years ago
Thank you @Raj.
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.
Mrunali said:
8 years ago
How x,y,z is 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;
Vikas said:
10 years ago
z worked here y=b does not affect previous and z=3 remains still then after decrements it become z=2.
Mohammad Mohsin said:
10 years ago
Here, y = b then all x, y and z will point to b and b = 2 as enum used.
And z-- makes no change because post decrement operator is used.
And z-- makes no change because post decrement operator is used.
Puru said:
1 decade ago
I don't understand how the reference variable's value is allowed to change. I read that a reference variable can't change its reference.
Could anyone explain?
Could anyone explain?
Abhishek said:
1 decade ago
Since we have use enum and we have declared 3 variables inside it.
1st one is initialized to 1, by enum property b=2, c=3.
All variables get increment by one thereafter.
For next part of answer see answer of D. S. Raghuram.
1st one is initialized to 1, by enum property b=2, c=3.
All variables get increment by one thereafter.
For next part of answer see answer of D. S. Raghuram.
Vicky said:
1 decade ago
What is the use of enum ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers