how to use enum datatype?Please explain me?

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


Please Help Members By Posting Answers For Below Questions

What is echo in c programming?

557


What is the difference between single charater constant and string constant?

624


What is #define in c?

622


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

940


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

632






What is wild pointer in c?

607


What is meant by high-order and low-order bytes?

656


Explain union.

638


What is variable declaration and definition in c?

503


write a program to generate address labels using structures?

4007


In which language linux is written?

604


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1507


Why doesnt this code work?

618


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

651


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?

1918