title: formal parameters and actual parameters in c
body: <p><strong>I just started learning functions and passing the parameters. so i am kind of new to this.</strong> Here, in the following programming, i am changing the values of <code>a[]</code> which is a formal parameter. even though, the sort function is not returning anything. how are the elements in <code>numberArray[]</code> are getting sorted even though the <code>sort</code> function just dealing with the formal parameters?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  void sort(int[],int);
  int main(void)
  {
    int n;
    printf("enter the number of elements : ");
    scanf("%d",&amp;n);
    int numberArray[n];
    printf("enter %d numbers :\n",n);
    for(int i=0;i&lt;n;i++)
      scanf("%d",&amp;numberArray[i]);
    sort(numberArray,n);
    printf("sorted list of numbers are :\n");
    for(int i=0;i&lt;n;i++)
      printf("%d\n",numberArray[i]);
    return 0;
  }
  void sort(int a[],int n)
  {
    int i,j,temp;
    for(i=0;i&lt;n-1;i++)
      {
        for(j=i+1;j&lt;n;j++)
          {
            if(a[i]&gt;a[j])
            {
              temp=a[j];
              a[j]=a[i];
              a[i]=temp;
            }
          }
      }
  }
  </code></pre>
  
  <p>I would like to compare the above program with a simple program as follows.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  void nothing(int);
  int main(void)
  {
      int a;
      printf("enter the value : ");
      scanf("%d",&amp;a);
      nothing(a);
      printf(" a = %d",a);
      return 0;
  }
  void nothing(int b)
      {
          b=b+2;
      }
  </code></pre>
  
  <p>In this program, the value of <code>a</code> is not changing. Why?</p>