title: In C++, is it better to use #define or const to avoid magic numbers?
body: <p>What are the advantages and disadvantages of using #define over const (and vice versa)?<br/></p>
  
  <p>When I read about bad programming practices specifically magic numbers, I found myself using #define more frequently. Some questions popped into my mind such as: </p>
  
  <p>Is it bad to use #define a lot?<br>
  Does it take memory space?<br>
  Would it be faster to use const instead?   </p>
  
  <p>I read a bit about this but I'm still not sure, from what I've understood:<br>
   #define defines a macro (not sure what macro means) and it deals with pre-processing. It replaces all instances of the defined keyword into something else before the code is being processed. const on the other hand is variable whose value cannot be changed midway during runtime.   </p>
  
  <p>The only reason I can think of using const is if the value relies on other variables. For example:</p>
  
  <pre><code>#define PI 3.14159f
  #define RADIUS 3.0f
  #define AREAOFCIRCLE PI*RADIUS*RADIUS
  </code></pre>
  
  <p>would be inefficient since every instance of AREAOFCIRCLE would be replaced by PI*RADIUS*RADIUS so the program would compute for it everytime you use AREAOFCIRCLE. On the other hand:</p>
  
  <pre><code>const float areaofcircle = PI*RADIUS*RADIUS;
  </code></pre>
  
  <p>would be more effecient since the program would  only compute for it once.   </p>
  
  <p>So back to the original question, how does #define compare to const?</p>