Wednesday 15 May 2013

Difference between define and enum

define
----------
#define - is called symbolic constants
 - this is the one  among processing unit
 - just replaces the value defined , at the first stage of building your code i.e preprocessing stage
 - values can't be looked in debuggers 
-  definition should followed always  upper letters

#define TRUE  1
#define FALSE 0

enum
-----
- collective of constant integers
- it's not a proprocessor,  enumeration happens in compilation stage

-  advantage is auto increment
eg: instead of
#define ONE 1
#define  TWO 2 etc

use enum val {
 ZERO,
ONE,
etc};

- value always starts from zero, until not defined 
- the values can be looked in debuggers
- can use upper / lower characters


Note that both #define and enum are constants, they don't  memory allotted.

No comments:

Post a Comment