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 are header files and what are its uses in C programming?
How does free() know explain how much memory to release?
What are the data types present in c?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
When should the const modifier be used?
What is the use of volatile?
What is the difference between struct and union in C?
List some of the static data structures in C?
How many main () function we can have in a project?
What is structure padding in c?
Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
Why are all header files not declared in every c program?
Explain how can you check to see whether a symbol is defined?
What is a keyword?
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?