Answer Posted / deepak mundhada
enum is a user defined data type . we have to use enum
keyword to specify it.
eg. #include<iostream.h>
class A
{ public:
enum Colour
{ colour_green=0,
colour_peach=0,
colour_white =1,
colour_yellow =2
};
//we cannot have color_green 2 times here
/*enum Colour
{ colour_green=0,
colour_peach=0,
colour_white =1,
colour_yellow =2,
colour_green=3, };
*/
//We cannot have another variable of same type as in enum
Colour
//as below
//int colour_yellow;
//We cannot have colour_white as it already declared in
enum Color
/*enum MyColour
{
colour_red, colour_white };
*/
//We cannot have another Struct or Union of same type as
below
//in the same scope
/*struct Colour
{ int red;
int green; };
*/
void compare(Colour colour1, Colour colour2);
};
void A::compare(A::Colour colour1, A::Colour colour2)
{ if(colour1 == colour2)
{ cout<<"colour1 and colour2 are same\n"; }
}}
int main()
{ A a;
a.compare(A::colour_green,A::colour_peach);
return(0);
}
Output:./a.out
colour1 and colour2 are same
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is echo in c programming?
What is the difference between single charater constant and string constant?
What is #define in c?
What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?
Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
What is wild pointer in c?
What is meant by high-order and low-order bytes?
Explain union.
What is variable declaration and definition in c?
write a program to generate address labels using structures?
In which language linux is written?
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
Why doesnt this code work?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?