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

Write a C program that computes the value ex by using the formula ex =1+x/1!+x2/2!+x3+3!+………….

1 Answers  


How can I rethow can I return a sequence of random numbers which dont repeat at all?

0 Answers  


WHAT IS RTGS N MINIMUM AMT TO B TRANSFERD N WHAT R THE CHARGES ON MINIMUM AMT N IN WHICH BANK WE CAN DO IT?

1 Answers  


What is the ANSI C Standard?

0 Answers   Celstream,


Why is malloc used?

1 Answers  






What is declaration and definition in c?

0 Answers  


4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.

0 Answers   TCS,


Differentiate between declaring a variable and defining a variable?

0 Answers  


What is difference between static and global variable in c?

0 Answers  


How to add two numbers without using semicolon at runtime

2 Answers  


write a statement to display all the elements array M(in reverse order? int M[8]={20,21,22,23,24,25,26,27};

5 Answers  


difference between loading and linking

1 Answers  


Categories