Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i <= zee; i++)
{
printf(“%d “, i);
}
return 0;
}

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i <= zee; i++)
{
printf(“%d “, i);
}
return 0;
}
a) 012
b) 123
c) compile time error
d) runtime error

Answer: c
Explanation: Enumeration variable ‘star’ appears two times in main() which causes the error. An enumaration constant must be unique within the scope.

Join The Discussion