0% found this document useful (0 votes)
1 views2 pages

Program 24

The document presents a C program that creates and utilizes a dynamic 1D array of integers. It prompts the user to input the size of the array, allocates memory for it, and allows the user to enter elements which are then displayed. The program also includes error handling for memory allocation failure and ensures that allocated memory is freed before exiting.

Uploaded by

jhapushpam.work
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Program 24

The document presents a C program that creates and utilizes a dynamic 1D array of integers. It prompts the user to input the size of the array, allocates memory for it, and allows the user to enter elements which are then displayed. The program also includes error handling for memory allocation failure and ensures that allocated memory is freed before exiting.

Uploaded by

jhapushpam.work
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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:

You might also like