Question:
What are enumerations?
Answer:
enumerations is one type of user defined data type Source: CoolInterview.com
Answered by: sekhar | Date: 7/30/2008
| Contact sekhar
Enums are group of symbolic constant each having some integer value.
enum(PASS_MARK=60,MERIT_MARK=70)
defines two symbolic constant PASS_MARK and MERIT_MARK as 60 and 70,- it could be done with #define as well.
However without specific values ,- the values are assigned automatically ,- starting with 0 for the first element and 1 for the second, 3 for the second etc.
In case if we state a number for the first element then it will increment the value of each consecutive elemts with '1'.
enum(MON=1,TUE,WED,THU,FRI,SAT,SUN);
gives the values of 1-7 to the names of days. Source: CoolInterview.com
Answered by: Andrew Gecse | Date: 2/10/2009
| Contact Andrew Gecse
enumerations can be used in place of a macros for example let us consider an example where a function is failing for many reasons like array out of bounds, divide by zero ,and memory allocation failure when you call such a function and if something goes wrong you may not know for what reason exactly in that case you can make an enum like enum error { ARRAY_OUT =0, MEMORY_FAIL, DIVIDE_ZERO } and so on instead of defining each one by macro Then based on return value it would be easy to locate eror . And ofcourse it is a user defined type.The values assigned will be from 0 to the number of elements present . you can also assign different values in between like enum week { sunday, monday, tuesday=4,wednesday,thursaday} then wednesday and thursday would have a value of 5 and 6
Source: CoolInterview.com
Answered by: shwetavg | Date: 6/3/2009
| Contact shwetavg
Enums are group of symbolic constant each having some integer value.
enum(PASS_MARK=60,MERIT_MARK=70)
defines two symbolic constant PASS_MARK and MERIT_MARK as 60 and 70,- it could be done with #define as well.
However without specific values ,- the values are assigned automatically ,- starting with 0 for the first element and 1 for the second, 3 for the second etc.
In case if we state a number for the first element then it will increment the value of each consecutive elemts with '1'.
enum(MON=1,TUE,WED,THU,FRI,SAT,SUN);
gives the values of 1-7 to the names of days. Source: CoolInterview.com
Answered by: ranjith | Date: 8/25/2010
| Contact ranjith
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|