alloc q4
- Create an array dynamically capable of storing 5 integers. Now use realloc so that it can now store 10 integers.
#include<stdlib.h>
int main() {
// Write C code here
float*ptr;
ptr=(float*) calloc( 5 ,sizeof(float));
//for (int i = 0 ; i<5;i++){
// printf("Enter value of element %d : ", i+1);
// scanf("%f",&ptr[i]);
//}
ptr=realloc(ptr , 10*sizeof(float));
for (int i = 0 ; i<10;i++){
printf("Enter value of element %d : ", i+1);
scanf("%f",&ptr[i]);
}
for (int i = 0 ; i<10;i++){
printf("%0.3f\n",ptr[i]);
}
return 0;
}
Comments
Post a Comment