473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

About enumeration

I am a bit confused here.

enum DAY /* Defines an enumeration type */
{
saturday, /* Names day and declares a */
sunday = 0, /* variable named workday with */
monday, /* that type */
tuesday,
wednesday, /* wednesday is associated with 3 */
thursday,
friday
} workday;

The value 0 is associated with saturday by default. The identifier sunday is explicitly set to 0. The remaining identifiers are given the values 1 through 5 by default.
So both Saturday and Sunday will have teh value as 0??
Please help me and if possible why we go for enumeration in C.
Oct 22 '07 #1
2 1181
I am a bit confused here.

enum DAY /* Defines an enumeration type */
{
saturday, /* Names day and declares a */
sunday = 0, /* variable named workday with */
monday, /* that type */
tuesday,
wednesday, /* wednesday is associated with 3 */
thursday,
friday
} workday;

The value 0 is associated with saturday by default. The identifier sunday is explicitly set to 0. The remaining identifiers are given the values 1 through 5 by default.
So both Saturday and Sunday will have teh value as 0??
Please help me and if possible why we go for enumeration in C.
The best way to answer that kind of questions is creating a program and print the values of Saturday and Sunday.

Enumerations are a great way to declare related constant values. Rather than declaring 7 constant integers "const int Sunday=0;", "const int Monday=1;", etc, etc, you use an enumeration that handles the assignation of values automatically.

Enumerations are heavily used in COM and .NET too.
Oct 22 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
The rule with values of enums is that a) they are named integer values and b) the count starts at 0 by default and increments for the next member.

If you assign a value, then it is incremented for the next enum member.

There is no check that values are duplicated.
Oct 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
22
by: James H. | last post by:
Greetings! I'm new to Python and am struggling a little with "and" and "or" logic in Python. Since Python always ends up returning a value and this is a little different from C, the language I...
8
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0"...
2
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
1
by: Stefano G. | last post by:
I have a WSDL containing this enumeration type <xsd:simpleType name="item_type_enum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="VCD"/> <xsd:enumeration value="SVCD"/>...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
37
by: mdh | last post by:
In one of the answers to a K&R exercise, the first couple of lines are: enum loop { NO, YES}; enum loop okloop=YES; I get the first line, but not the second. Sorry about the LOL question. ...
9
by: news.microsoft.com | last post by:
I am looping through an iteration and I would like to test the next item but if its not the one that I want how do I put it back so that when my foreach continues it is in the next iteration? ...
1
by: Wayne Shu | last post by:
Today when I read TC++PL(se) section 4.8 Enumerations, I get some problems. 1. In an enumeration, why the value of some enumerators can be the same, for instance: enum e1{a = 0, b = 0, c = 0};...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.