ccplusplus.com
Learn C, C++ Concepts
Tuesday, February 14, 2012
using enum as array index c
/************************************************************************* * File : enum-as-array-index.c * Author : Saurabh Guptas * Desc : using enum as array index c * Source : http://ccplusplus.com/p/c.html * Created : 6:04 PM Tuesday, February 14, 2012 *************************************************************************/ #include
enum StudentNames { KENNY, // 0 KYLE, // 1 STAN, // 2 BUTTERS, // 3 CARTMAN, // 4 WENDY, // 5 MAX_STUDENTS // 6 }; int main () { int i = 0; int anScores[MAX_STUDENTS]; // allocate 6 integers anScores[STAN] = 76; printf ("anScores [STAN] = %d\n", anScores [STAN]); return 0; } /* * OUTPUT * [sgupta@rhel6x86 c]$ c++ enum-as-array-index.c -o enum-as-array-index [sgupta@rhel6x86 c]$ ./enum-as-array-index anScores [STAN] = 76 [sgupta@rhel6x86 c]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment