by Dinesh Thakur Category: Array
#include <stdio.h>

#include <conio.h>
#include <stdlib.h>
main()
{
  int i, n;
  int *arr;
  clrscr();
  printf("\n Enter the number of elements ");
  scanf ("%d", &n);
  arr= (int*)malloc(n * sizeof(int));
   if(arr ==NULL)
   {
     printf("\n Memory Allocation Failed");
     exit(0);
   }
     for(i=0;i<n;i++)
     {
       printf("\n Enter the value %d of the array: ",i );
       scanf("%d", &arr[i]);
     }
      printf("\n The array contains \n");
       for (i=0; i<n; i++)
             {
              printf(" \n \t%d \t", arr[i]);
              /*another way is to write *(arr+i)  */
             }
return 0;
}

Allocate space dynamically for the array



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles