in C Plus Plus by
Which is better #define or enum?

1 Answer

0 votes
by

  • 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.
...