top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is ENUM in C and how it is different from Integers?

+1 vote
407 views
What is ENUM in C and how it is different from Integers?
posted Jul 21, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

enum day {SUN,MON, TUE, WED, THU, FRI, SAT};
enum day rday;

First Line Creates “User Defined Data Type” called day and has 7 values as given in the pair of braces.
In the second line “rday” variable is declared of type “day” which can be initialized with any “data value amongst 7 values”.
Default Numeric value assigned to first enum value is “0”. So SUN is given value “0”.
MON is given value “1”.
TUE is given value “2”.
WED is given value “3”.
THU is given value “4”.
FRI is given value “5”.
SAT is given value “6”.

Now say rday=MON;
then printf("%d", rday); would be 1.

Enumerated values are converted into integer values internally by the compiler and provide the flexibility and readability to the code. The only difference would be the size (size of the enum is compiler dependent and not necessary be equal to int).

answer Jul 22, 2015 by Salil Agrawal
enum stands for enumerated variable or constant and the difference between integer is only  the integer is any integer value and the enum is any constant value or anything which will constant.
Thanks Mohit for clarifying more and enhancing the answer :)
Similar Questions
+1 vote

I was searching the differences in normal C-lang multithread program and a multicore programming. Can any one clarify the difference and how the "parallelism" OR "execution-speed" is achieved form multicore programming.

Using the thread attribute we can set the affinity(in which core he has to run) to the thread, not not getting the exact usage of multicore programming.

One more question how to access the common(global data) memory in multicore programming, will synchronization adds delay in execution? If yes then what is the use of multicore programming

+3 votes

Any C implementation of named pipe would be helpful?

+1 vote

This was asked today at Amazon interview -

Given two Binary Trees (not BST). Each node of both trees has an integer value. Validate whether both trees have the same integers, there could be repetitive integers.

Example
Tree1:
5
1 6
5 4 3 6

Tree2:
1
3 4
6 5

Output
Identical integers

Sample C/C++/Java code would be helpful.

...