Diiference Between Enum and #define
HI all ,
[B]What is the difference between enum and #define ? [/B]
I know as enum will give integer value and #define is a macro which help to replacement of string.
[COLOR="Blue"]So my doubt is :--
enum bool { YES, NO}; mean value of YES == 0 and NO ==1
#define NO 1
#define YES 0[/COLOR]
So from above two , what is the difference between enum and #define ?
Thanks in Advance,
-Amaresh
Re: Diiference Between Enum and #define
At the present time, there is little difference. Although many people might have wished otherwise, the ANSI standard says that enumerations may be freely intermixed with integral types, without errors. (If such intermixing were disallowed without explicit casts, judicious use of enums could catch certain programming errors.)
Some advantages of enums are that the numeric values are automatically assigned, that a debugger may be able to display the symbolic values when enum variables are examined, and that they obey block scope. (A compiler may also generate nonfatal warnings when enums and ints are indiscriminately mixed, since doing so can still be considered bad style even though it is not strictly illegal). A disadvantage is that the programmer has little control over the size (or over those nonfatal warnings).