title: What is the difference between a macro and a const in C++?
body: <p>I was asked this question in a technical interview:</p>
  
  <blockquote>
    <p>What is the difference between a <code>const</code> and a macro in C++?</p>
  </blockquote>
  
  <p>My answer was that a macro is a preprocessor directive and it could be difficult to debug the application if you use a macro since it is replaced with the constant expression before compilation, whereas a <code>const</code> can have a type identifier and is easy to debug.</p>
  
  <p>Could anyone point out any other difference and which should be preferred?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>From the IBM documentation for C++:</p>
  
  <blockquote>
    <p>The following are some differences between <code>#define</code> and the <code>const</code> type qualifier:</p>
    
    <ol>
    <li><p>The <code>#define</code> directive can be used to create a name for a numerical, character, or  string constant, whereas a const object of any type can be declared.</p></li>
    <li><p>A const object is subject to the scoping rules for variables, whereas a constant created using <code>#define</code> is not. Unlike a <code>const</code> object, the value of a macro does not appear in the intermediate source code used by the compiler because they are expanded inline. The inline expansion makes the macro value unavailable to the debugger.</p></li>
    <li><p>A macro can be used in a constant expression, such as an array bound, whereas a <code>const</code> object cannot.  (I think we surely need to use macro to define <code>array_size</code>.</p></li>
    <li><p>The compiler does not type-check a macro, including macro arguments.</p></li>
    </ol>
  </blockquote>