how to use enum datatype?Please explain me?
Answers were Sorted based on User's Feedback
Answer / gsrinivas
enum data type usally user defined.
for ex:
enum{sunday,monday,tuesday};
enum x;
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / 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 |
Answer / praphulla
It automatically passes values to declared varibles.
ex: enum{red,green,blue}
| Is This Answer Correct ? | 0 Yes | 0 No |
How can I get back to the interactive keyboard if stdin is redirected?
how many times of error occur in C
what does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);}
wats the diference btwen constant pointer and pointer to a constant.pls give examples.
What is abstract data structure in c?
what is the coding of display the factorial of a number using array and function?
What is the full form of getch?
What are pointers in C?
A stack can be implemented only using array?if not what is used?
What is volatile in c language?
How do I determine whether a character is numeric, alphabetic, and so on?
Write a program to compare two strings without using the strcmp() function
42 Answers Accenture, Arba Minch University,