title: Pointers in C (Passing addresses into function)
body: <p>I'm trying have a crack at this problem. The question says, *"swap_nums seems to work, but not swap_pointers. Fix it."* I'm a beginner by the way :)</p>
  
  <p>I believe I can work the solution out myself but the trouble is I have a bit of difficulty understanding some programming concepts in C. Here I have shown the given code that requires editing. Below that I will show my thought processes so far. Please note: I want some hints NOT the full solution please. :-)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void swap_nums(int *x, int *y);
  void swap_pointers (char *x, char *y);
  
  int main (int argc, char *argv[]){
  
     int a = 3, b = 4;
     char *s1, *s2;
     swap_nums(&amp;a, &amp;b);
     printf("a is %d\n", a);
     printf("b is %d\n", b);
  
     s1 = "I should print second";
     s2 = "I should print first";
  
     swap_pointers(s1, s2);
     printf("s1 is %s\n", s1);
     printf("s2 is %s\n", s2);
  
     return EXIT_SUCCESS; } 
  
  void swap_nums(int *x, int *y){
  
     int temp;
     temp = *x;
     *x = *y;
     *y = temp; }
  
  void swap_pointers (char *x, char *y){
  
     char *temp;
     temp = x;
     x = y;
     y = temp; }
  </code></pre>
  
  <p>My thought process: This is a program that I believe will supposedly swap the integer variables a and b. It will then take the two declared strings and swap them as well.</p>
  
  <p>Main function:</p>
  
  <pre><code>int a = 3, b = 4;
  </code></pre>
  
  <p>Assigns variable a and b to 3 and 4 respectively.</p>
  
  <pre><code>char *s1, *s2;
  </code></pre>
  
  <p>Creates a character pointer variable (which will hold the address of a character)</p>
  
  <pre><code>swap_nums(&amp;a, &amp;b);
  </code></pre>
  
  <p>The function swap_nums is taking place. I will go to it now to explain my thought processes.</p>
  
  <pre><code>void swap_nums(int *x, int *y){
  </code></pre>
  
  <p>So I'm not that familiar with passing things into functions, could someone correct what I am about to say if I am wrong here?</p>
  
  <p>The way I see it, we are passing the addresses of a and b as indicated by the ampersand into the function swap_nums. But how come the we have int *x and int *y? I'm a bit confused here. Could someone explain to me this bit?</p>