Home
Recent Q&A
Java
Cloud
JavaScript
Python
SQL
PHP
HTML
C++
Data Science
DBMS
Devops
Hadoop
Machine Learning
Azure
Blockchain
Devops
Ask a Question
Which is better #define or enum?
Home
C Plus Plus
Which is better #define or enum?
asked
Jan 6
in
C Plus Plus
by
GeorgeBell
Which is better #define or enum?
c-interview-questions-answers
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
Jan 6
by
GeorgeBell
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.
...