Write a C program to dynamically allocate memory in an array and insert new element at specified position. code example
Example 1: how to dynamically allocate array size in c
int *p_array;
double *d_array;
p_array = (int *)malloc(sizeof(int)*50);
d_array = (int *)malloc(sizeof(double)*100);
for(i=0; i < 50; i++) {
p_array[i] = 0;
}
double *dptr = d_array;
for(i=0; i < 50; i++) {
*dptr = 0;
dptr++;
}
Example 2: c++ program to input and print text using Dynamic Memory Allocation.loop
program to input and print text using Dynamic Memory Allocation.