title: The need for parentheses in macros in C
body: <p>I tried to play with the definition of the macro <code>SQR</code> in the following code:</p>
  
  <pre><code>#define SQR(x) (x*x)
  int main()
  {
      int a, b=3;
      a = SQR(b+5);      // Ideally should be replaced with (3+5*5+3), though not sure.
      printf("%d\n",a);
      return 0;
  }
  </code></pre>
  
  <p>It prints <code>23</code>. If I change the macro definition to <code>SQR(x) ((x)*(x))</code> then the output is as expected, <code>64</code>. I know that a call to a macro in C replaces the call with the definition of the macro, but I still can’t understand, how it calculated <code>23</code>.</p>