WAP dynamic memory example? BCA-2nd semester


 Dynamic memory example ( pointer)

#include<studio.h>

#include<conio.h>

#include<stdlib.h>

 void main ()

{

int n, I, *p,s=0;

printf ("enter number");

scanf ("%d",& n);

p= (int*) malloc (n* size of (int));

if( p==null)

{

printf("error! memory not allocated");

 exit(0);

}

printf ("enter element of array");

for (I=0;I<n;i++)

{

 scanf ("%d", p+i);

sum+=*(p+i);

}

printf ("%d", sum);

free(p);

getch ();

}

No comments:

Post a Comment

If you have any doubts, Please lets me know and Please Follow our Website