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

前端 未结 7 1662
长情又很酷
长情又很酷 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:43

    Macros don't respect scope, and a macro's name may not be available to a symbolic debugger. Dan Saks has a fairly complete article on the relative merits of macros (none), constant objects, and enumeration constants. Like Stephen Dewhurst, Saks prefers enumeration constants for integer values since they take up no storage (more precisely, enumeration constants have neither storage duration nor linkage).

提交回复
热议问题