Program 24: WAP to create and use a dynamic 1D array of integers.
Code:
#include <stdio.h>
#include <stdlib.h>
void main(){
int size,elements,i;
int* arr;
printf("The address of arr is : %llu \n",&arr);
printf("Enter the Size of the Array : ");
scanf("%d",&size);
arr = (int* ) malloc(sizeof(int)*size);
if (arr==NULL){
free(arr);
printf("Memory is not allocated ");
}
else {
printf("Entering the Elements of the Array \n");
for(i=0;i<size;i++){
printf("Enter Element a[%d]: ",i);
scanf("%d",&arr[i]);
}
printf("Displaying the Array \n");
for(i=0;i<size;i++){
printf("a[%d] : %d \n",i,arr[i]);
}
}
free(arr);
}
OUTPUT: