1.

Which is better #define or enum?

Answer»
  • If we let it, the COMPILER can build enum values AUTOMATICALLY. However, each of the defined values must be given separately.
  • Because macros are preprocessors, UNLIKE enums, which are compile-time entities, the source code is unaware of these macros. So, if we use a debugger to debug the code, the enum is superior.
  • Some compilers will GIVE a warning if we use enum values in a switch and the default CASE is missing.
  • Enum always generates int-type identifiers. The macro, on the other hand, allowed us to pick between various integral types.
  • Unlike enum, the macro does not have a defined scope constraint.


Discussion

No Comment Found