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
Does sprintf put null character?
Without Computer networks, Computers will be half the use. Comment.
What are high level languages like C and FORTRAN also known as?
What is a pragma?
What is the importance of c in your views?
Explain the difference between strcpy() and memcpy() function?
What does void main () mean?
Explain 'bus error'?
write a program to copy the string using switch case?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
How is a pointer variable declared?
What is string length in c?
#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }
main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above
How will you find a duplicate number in a array without negating the nos ?