Free
Sun May 14 2023 08:41:48 GMT+0000 (Coordinated Universal Time)
Saved by
@prachi
#include<stdio.h>
#include<stdlib.h>
int main(){
int *arr;
int *arr1;
int i,n,m;
printf("Enter no of elements:");
scanf("%d",&n);
printf("Entered no is:%d",n);
arr = (int*)malloc(n * sizeof(int));
if(arr == NULL){
printf("\nMemory not allocated");
exit(0);
}
else{
printf("\nMemory successfully allocated using malloc");
for(i=0;i<n;++i){
arr[i] = i + 1;
}
free(arr);
printf("\nArray Freed\n");
//new array
printf("\nEnter no of new elements:");
scanf("%d",&m);
printf("Entered no is:%d",m);
arr = (int*)malloc(m * sizeof(int));
if(arr == NULL){
printf("\nMemory not allocated");
exit(0);
}
else{
printf("\nMemory successfully allocated using malloc");
for(i=0;i<m;++i){
arr[i] = i + 1;
}
printf("\nElement of array are: ");
for(i=0;i<m;++i){
printf("%d,",arr[i]);
}
printf("\nAddress of array are: ");
for(i=0;i<m;++i){
printf("%d,",&arr[i]);
}
}
return 0;
}
}
content_copyCOPY
Comments