title: "Address of" (&) an array / address of being ignored be gcc?
body: <p>I am a teaching assistant of a introductory programming course, and some students made this type of error:</p>
  
  <pre><code>char name[20];
  scanf("%s",&amp;name);
  </code></pre>
  
  <p>which is not surprising as they are learning... What is surprising is that, besides gcc warning, the code works (at least this part). I have been trying to understand and I wrote the following code:</p>
  
  <pre><code>void foo(int *v1, int *v2) {
    if (v1 == v2)
      printf("Both pointers are the same\n");
    else
      printf("They are not the same\n");
  }
  
  int main() {
    int test[50];
    foo(&amp;test, test);
    if (&amp;test == test)
      printf("Both pointers are the same\n");
    else
      printf("They are not the same\n");
  }
  </code></pre>
  
  <p>Compiling and executing:</p>
  
  <pre><code>$ gcc test.c -g
  test.c: In function ‘main’:
  test.c:12: warning: passing argument 1 of ‘foo’ from incompatible pointer type
  test.c:13: warning: comparison of distinct pointer types lacks a cast
  $ ./a.out 
  Both pointers are the same
  Both pointers are the same
  </code></pre>
  
  <p>Can anyone explain why they are not different?</p>
  
  <p>I suspect it is because I cannot get the address of an array (as I cannot have <code>&amp; &amp;x</code>), but in this case the code should not compile.</p>
  
  <p>Edit: I know that an array by itself is the same as the address of the first element, but this is not related to this problem, I think. For example:</p>
  
  <pre><code>int main() {
    int a[50];
    int * p = a;
    printf("%d %d %d\n", p == a, p == &amp;a[0], &amp;p[0] == a);
    printf("%d %d %d\n", p == &amp;a, &amp;p == a, &amp;p == &amp;a);
  }
  </code></pre>
  
  <p>prints:</p>
  
  <pre><code>$ ./a.out 
  1 1 1
  1 0 0
  </code></pre>
  
  <p>I don't understand why the second line begins with <code>1</code>.</p>