free dynamic memory allocation
#include <stdio.h>
#include <stdlib.h>
int main(){
//printf("The size of int in your computer is %d\n",sizeof(int));
// printf("The size of float in your computer is %d\n",sizeof(float));
// printf("The size of char in your computer is %d\n",sizeof(char));
int * ptr;
int * ptr2;
int n;
printf("Enter the size of array:\n");
scanf("%d",&n);
ptr=(int *) malloc(n*sizeof(int));
for(int i=0;i<600;i++)
{
ptr2=(int *) malloc(60000*sizeof(int));
printf("Enter the value of element %d:\n",i+1);
scanf("%d",&ptr[i]);
free(ptr2);
}
for(int i=0;i<600;i++)
{
printf("The value of element %d is:%d\n",i+1,ptr[i]);
}
return 0;
}
Comments
Post a Comment