how to use enum datatype?Please explain me?

Answers were Sorted based on User's Feedback



how to use enum datatype?Please explain me?..

Answer / gsrinivas

enum data type usally user defined.
for ex:
enum{sunday,monday,tuesday};
enum x;








Is This Answer Correct ?    4 Yes 0 No

how to use enum datatype?Please explain me?..

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

how to use enum datatype?Please explain me?..

Answer / praphulla

It automatically passes values to declared varibles.
ex: enum{red,green,blue}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

How can I find out if there are characters available for reading?

0 Answers  


please can some one guide me, to the answer Write a C program to enter 15 numbers as an input from the keyboard and program will find and print odd numbers and their average. i have studied while and do while loop for loop if and else if switch

2 Answers  


write a proram to reverse the string using switch case?

0 Answers   Syntel,


where do we use volatile keyword?

1 Answers  


How can I split up a string into whitespace-separated fields?

0 Answers  






What are the 5 elements of structure?

0 Answers  


What is static and auto variables in c?

0 Answers  


struct abc { unsigned int a; char b; float r; }; struct xyz { int u; struct abc tt; }ww; ww = (struct xyz*)malloc(sizeof(struct xyz)); will the memory be allocated for the inner structure also?

1 Answers   Wipro,


What is sizeof int in c?

0 Answers  


What is string function in c?

0 Answers  


What is volatile, register definition in C

0 Answers   Cognizant,


In the below code, how do you modify the value 'a' and print in the function. You'll be allowed to add code only inside the called function. main() { int a=5; function(); // no parameters should be passed } function() { /* add code here to modify the value of and print here */ }

1 Answers  


Categories