What is the difference between a macro and a const in C++?

前端 未结 7 1650
长情又很酷
长情又很酷 2020-12-01 02:08

I was asked this question in a technical interview:

What is the difference between a const and a macro in C++?

My a

相关标签:
7条回答
  • 2020-12-01 02:58

    A macro always have a type, for instance, #define FIVE 5 is of type int.

    An advantage for the const variable over the macro could be the memory usage : With a macro the value may have to be duplicated everywhere it is used will a const variable will not be duplicated in memory. (but I am not sure of this difference)

    0 讨论(0)
提交回复
热议问题