Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   what is the base type of enum (http://www.programmingforums.org/showthread.php?t=13780)

amitpansuria Aug 17th, 2007 12:27 AM

what is the base type of enum
 
helo i have asked in exam what that what is the base type of
enum
options are given bewlo
(1) long int
(2) short int
(3) signed int
(4) unsigned int

can u tell me what is the exact answer from the above option
Regards,
Amit

lectricpharaoh Aug 17th, 2007 1:07 AM

I think the answer you're looking for is int. However, while an enum can be assigned to an int without loss of data or a cast, this doesn't mean it's the same thing.

[edit] I didn't say signed int, but since that is implicit unless you specify unsigned, I figured it was obvious. Thus, the teacher was probably looking for choice #3. [/edit]

grumpy Aug 17th, 2007 1:28 AM

The teacher should be taken out and summarily shot for asking that question in that form. The correct answer is "(5) any integral type, including any of those above". And because the term "base type" has no meaning when discussing enumerations.

An enum is a distinct type with named constant integral values. The underlying type (a term used in the standard to represent an integral type that can represent all the values defined in an enumeration) is implementation defined (i.e. it depends on the compiler). Even more importantly, the underlying type can depend on the enumeration, depending on what values they hold -- so a particular compiler can support multiple underlying types, and select them appropriately for each enumerated type.

That said, if a teacher has asked that question, s/he probably thinks the answer is "(3) signed int". So you have the choice of giving the answer the teacher expects or the correct one. That choice needs to be based on consequences to the student (eg being marked down), not on correctness.

Jessehk Aug 17th, 2007 1:31 AM

Quote:

Originally Posted by grumpy (Post 132319)
So you have the choice of giving the answer the teacher expects or the correct one.

Don't you just hate when that happens? :p

lectricpharaoh Aug 17th, 2007 4:59 AM

I've had a (very) few teachers who were willing to adjust their marking if you could make a case as to why your answer was correct. Such teachers seem to be in the minority, but if you're lucky enough to have one, I'd raise the point that the answer is none of the above, as grumpy points out. Otherwise, suck it up and answer '#3'.


All times are GMT -5. The time now is 3:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC