ccplusplus.com
Learn C, C++ Concepts
Friday, February 10, 2012
enum c example
/************************************************************************* * File : enumeration.c * Author : Saurabh Gupta * Desc : enum c example * Source : http://www.ccplusplus.com/p/c.html * Created : 11:32 AM Friday, February 10, 2012 *************************************************************************/ #include
/* * By default, the first enumerator is assigned the integer value 0, * and each subsequent enumerator has a value one greater than the * previous enumerator */ enum WeekDay { Monday, // assigned 0 Tuesday, // assigned 1 Wednesday, // assigned 2 Thursday, // assigned 3 Friday, // assigned 4 Saturday, // assigned 5 Sunday // assigned 6 }; int main () { WeekDay day = Monday; for (int day = Monday; day < Sunday; day++) { printf ("%d\n",day); } return 0; } /* * OUTPUT * [sgupta@rhel6x86 enum]$ gcc enumeration.c -o enumeration [sgupta@rhel6x86 enum]$ ./enumeration 0 1 2 3 4 5 [sgupta@rhel6x86 enum]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment