![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2007
Posts: 13
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,292
Rep Power: 5
![]() |
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]
__________________
Java? Rant? Me? Noooo.... |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,318
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#4 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 655
Rep Power: 4
![]() |
Don't you just hate when that happens? :p
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#5 |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,292
Rep Power: 5
![]() |
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'.
__________________
Java? Rant? Me? Noooo.... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do I take a square root? | Fall Back Son | C | 26 | Oct 23rd, 2006 1:24 PM |
| Pointer return type,.. ??? | Mack1982 | C++ | 28 | May 26th, 2006 9:02 PM |
| C# corruption!!! | Kilo | C++ | 32 | May 21st, 2006 9:44 PM |
| Command Prompt | SkyPioneer | Coder's Corner Lounge | 5 | May 3rd, 2006 11:07 PM |
| base type has incomplete type | Eric the Red | C++ | 4 | Mar 3rd, 2006 9:04 PM |