title: Encountering error "The NTVDM CPU has encountered an illegal instruction" while using pointer
body: <p>While creating a program for mergesort, i encountered an error while using pointer instead of array. The following code runs correctly:</p>
  
  <pre><code>void main()
  {
      clrscr();
      int n,i,A[100];
      cout&lt;&lt;"Enter the value of n: ";
      cin&gt;&gt;n;
      cout&lt;&lt;"\nEnter the array: ";
          for(i=0;i&lt;n;i++)
          cin&gt;&gt;A[i];
      mergesort(A,0,n-1);
      cout&lt;&lt;"Sorted array is: ";
      for(i=0;i&lt;n;i++)
          cout&lt;&lt;A[i]&lt;&lt;" ";
      getch();
  }
  </code></pre>
  
  <p>But when i replace A[100] by *A in main i.e. when main definition becomes following:</p>
  
  <pre><code>void main()
  {
      clrscr();
      int n,i,*A;
      cout&lt;&lt;"Enter the value of n: ";
      cin&gt;&gt;n;
      cout&lt;&lt;"\nEnter the array: ";
      for(i=0;i&lt;n;i++)
          cin&gt;&gt;A[i];
      mergesort(A,0,n-1);
      cout&lt;&lt;"Sorted array is: ";
      for(i=0;i&lt;n;i++)
          cout&lt;&lt;A[i]&lt;&lt;" ";
      getch();
  }
  </code></pre>
  
  <p>then also program gives correct output, but before exiting the console window it gives the error "<strong>The NTVDM CPU has encountered an illegal instruction</strong>". When i put array input code in separate function then i don't get the above error i.e. when code becomes following:</p>
  
  <pre><code>int getList(int* A)
  {
      int n;
      cout&lt;&lt;"\nEnter the value of n: ";
          cin&gt;&gt;n;
      cout&lt;&lt;"\nEnter the array: ";
      for(int i=0;i&lt;n;i++)
          cin&gt;&gt;A[i];
      return n;
  }
  
  void main()
  {
      clrscr();
      int n,*A;
      n=getList(A);
      mergesort(A,0,n-1);
      cout&lt;&lt;"Sorted array is: ";
      for(int i=0;i&lt;n;i++)
          cout&lt;&lt;A[i]&lt;&lt;" ";
      getch();
  }
  </code></pre>
  
  <p>then i don't get illegal instruction error. Can somebody please help?</p>