-
Junior Member
Diiference Between Enum and #define
HI all ,
What is the difference between enum and #define ?
I know as enum will give integer value and #define is a macro which help to replacement of string.
So my doubt is :--
enum bool { YES, NO}; mean value of YES == 0 and NO ==1
#define NO 1
#define YES 0
So from above two , what is the difference between enum and #define ?
Thanks in Advance,
-Amaresh
-
Expert Member
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).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules