title: C function returns const pointer that is assigned to nonconst pointer - warning not error
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  const int * func()
  {
      int * i = malloc(sizeof(int));
      (*i) = 5;    // initialize the value of the memory area
      return i;
  }
  
  int main()
  {
      int * p = func();
      printf("%d\n", (*p));
      (*p) = 3;       // attempt to change the memory area - compiles fine
      printf("%d\n", (*p));
      free(p);
      return 0;
  }
  </code></pre>
  
  <p>Why does the compiler allow me to change <code>(*p)</code> even if <code>func()</code> returns a const pointer?</p>
  
  <p>I'm using gcc, it shows only a warning on the <code>int * p = func();</code> line : "warning: initialization discards qualifiers from pointer target type".</p>
  
  <p>Thanks.</p>