title: Two integer variables residing at one memory address?
body: <p>I am learning pointers in C, and am trying to solve exercises on pointers available online. Although the below question doesn't make use of pointers, I understand that the incorrect output is due to lack of usage of pointers. Here is the question- </p>
  
  <pre><code>/* p2.c 
  Find out (add code to print out) the address of the variable x in foo1, and the 
  variable y in foo2. What do you notice? Can you explain this? 
  */
  </code></pre>
  
  <p>And here is my answer- </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void foo1(int xval) 
  { 
   int x; 
   x = xval; 
   /* print the address and value of x here */ 
   printf("\n Address of variable x is:%p\n", &amp;x);
   printf("\n Value of variable x is: %d\n", x); 
  
  } 
  void foo2(int dummy) 
  { 
   int y;
   y=dummy; 
   /* print the address and value of y here */ 
   printf("\n Address of variable y is:%p\n", &amp;y);
   printf("\n Value of variable y is: %d\n", y); 
  } 
  
  int main() 
  { 
   foo1(7); 
   foo2(11); 
  
   return 0; 
  } 
  </code></pre>
  
  <p>The output when compiling the program is- </p>
  
  <pre><code> Address of variable x is:0x7fff558fcb98
  
   Value of variable x is: 7
  
   Address of variable y is:0x7fff558fcb98
  
   Value of variable y is: 11
  </code></pre>
  
  <p>From what I understand, when the program runs, and <code>foo1</code> with an integer as function argument is called, the integer <code>7</code> is taken and stored in the integer variable <code>x</code>. The function <code>foo1</code> then prints the address and value of variable <code>x</code>. Same thing repeats with function <code>foo2</code>.</p>
  
  <p>But, I couldn't understand how is it that two integer variables with different values are residing at the same memory address <code>0x7fff558fcb98</code>? Is it because of memory management issues in C (<code>malloc</code>, <code>free</code> etc-I'm not there yet!)? </p>
  
  <p>Any help would be highly appreciated. Thank You.</p>