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)
Prerak said:
1 decade ago
x=3
y=3
z=3
y=2 i.e.
x=2 i.e.
z=2
And decrement operator will effect only after the output !
Thus output = 2.
But z = 1.
y=3
z=3
y=2 i.e.
x=2 i.e.
z=2
And decrement operator will effect only after the output !
Thus output = 2.
But z = 1.
Anonymous said:
1 decade ago
Why the value of x, y, z is 3?
Honey Garg said:
1 decade ago
Because here we used enum. In enum when we initialized variable the value will be in incremented order.
D.s.raghuram said:
1 decade ago
In enum here a=1,hence then b will be 2 and c will be 3.
x=3.
y=3.
z=3.
y=2 i.e.
x=2 i.e.
z=2.
And decrement operator will effect only after the output !
Thus output = 2.
x=3.
y=3.
z=3.
y=2 i.e.
x=2 i.e.
z=2.
And decrement operator will effect only after the output !
Thus output = 2.
Zubair Bhatti said:
1 decade ago
Why we use enum?
Vicky said:
1 decade ago
What is the use of enum ?
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.
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?
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers