adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Dynamic allocation of memory using malloc() function

Dynamic  allocation of memory using malloc() function


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
  void main()
   {
       int *ptr,n,i;
       printf("Enter the number of integer to be entered :-");
       scanf("%d",&n);
       ptr=(int*)malloc(n*sizeof(int));
       if(ptr==NULL)
        {
            printf("Memory not available.");
            exit(0);
        }
      printf("Enter %d numbers:-",n);
      for(i=0;i<n;i++)
      scanf("%d",ptr+i);
      printf("Entered numbers is :-");
      for(i=0;i<n;i++)
      printf("%3d",*(ptr+i));
      free(ptr);
    getch();
   }
Output:-





Post a Comment

0 Comments