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

simple c program for 12345 convert 54321 with out using string

7 Answers   TCS,


WAP TO ACCEPT STRING AND COUNT A COMES N TIMES B COMES N TIMES C COMES N TIMES D COMES N TIMES AND SO ON......... AT LAST UNTIL Z COMES N TIMES...............

3 Answers  


cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration

0 Answers  


1. main() { printf("%d",printf("HelloSoft")); } Output?

3 Answers   HCL,


main() { char *p; p="Hello"; printf("%c\n",*&*p); }

2 Answers   ME,






What is a null string in c?

0 Answers  


How many loops are there in c?

0 Answers  


what is the output of the following code? main() { int I; I=0x10+010+10; printf("x=%x",I); } give detailed reason

3 Answers  


what are advantages of U D F?

1 Answers   Google,


Do you know the difference between malloc() and calloc() function?

0 Answers  


what is the use of using linked list and array?

10 Answers   Infosys, TCS,


Program to swap the any two elements in an array containing N number of elements?

1 Answers   Bosch, Glenwood, Ugam Solutions,


Categories