Results 1 to 2 of 2

Thread: Diiference Between Enum and #define

  1. #1
    Junior Member
    Join Date
    Dec 2008
    Answers
    10

    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


  2. #2
    Expert Member
    Join Date
    Nov 2008
    Answers
    300

    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
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact