C++ Programming - References - Discussion

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

Shyam said:   1 decade ago
Enum variables cannot be changed once they are defined at r=++c it results a error.

Atul Kumar said:   1 decade ago
Because the value of the enum variables will be as
a=0 b=1 c=2.

But as given r=++c means c=3 but c=3 can't be possible Because last value is 2.

Lavanyeswari motupalli said:   1 decade ago
enum is a user defined keyword which is used to hold set of constants so the variables in enum (a,b,c) can't be altered i.e r=++c (give error).

Deepthi mayi said:   8 years ago
Attempt to change the values of enum variables may result in compile time error.
(2)

Vamshi said:   7 years ago
#include<iostream.h> is unvalid header in both c and c++.

And in r=++c instruction c is an enum. We can't increase enum values.

Post your comments here:

Your comments will be displayed after verification.