LEC20081110 - Introduction to Computer Programming November...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Computer Programming November 10, 2008 CSC180 Fall 2008, University of Toronto Enumeration constants and variables An enumeration is a list of constant integer values (enumerators). Enumeration variables and enumeration constants are integers. In default, the first enumeration constant has value 0, the next 1, and so on. Enumeration constant values can be specified explicitly; unspecified constant values is one greater than the previous constant. Subject to scope rules CSC180 Fall 2008, University of Toronto 1 Example: /* s and s2 are treated as integer variables */ enum {CLUBS, DIAMONDS, HEARTS, SPADES} s, s2; s = CLUBS; s2 = SPADES; printf("%d\n", s + s2); /* print 3 */ s++; /* OK */ s += 10; /* OK */ enum boolean {NO, YES} b; b = NO; /* b has value 0 */ enum escapes {BELL = \a, BACKSPACE = \b, TAB = \t, NEWLINE = \n, VTAB = \v, RETURN = \r}; enum escapes e; CSC180 Fall 2008, University of Toronto 2 e = TAB; typedef enum months {JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC} Months; Months m; m = FEB; /* m has value 2 */ printf("%d\n", AUG); /* print 8 */ typedef enum { CS_NONE, /* used for reporting errors, etc */ CS_ISO8859_1, CS_ISO8859_1_X11, /* X font encoding with VT100 glyphs */ CS_ISO8859_2, CS_ISO8859_3, CS_ISO8859_4 } charset_t; charset_t type = CS_ISO8859_4; CSC180 Fall 2008, University of Toronto 3 The advantages over macro definitions: (1) constant values can be generated automatically; (2) debugger may print values of enumeration variables in their symbolic form....
View Full Document

This note was uploaded on 01/10/2011 for the course CSC 180 taught by Professor Na during the Fall '01 term at University of Toronto- Toronto.

Page1 / 19

LEC20081110 - Introduction to Computer Programming November...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online