Dynamic array in C

Dynamic array is a array that has a fixed number of items on it, but the space required for data storage is alloted at runtime on data input. The code below will demonstrate how we can use dynamic array in C # include<stdio.h> # include<stdlib.h> int main() { int *arr[10], i; printf("Enter 10 numbers\n"); for(i = 0; i < 10; i++){ //asking for space to store an int arr[i] = (int*) malloc(sizeof(int)); scanf("%d", arr[i]); } printf("the array you entered is "); for(i = 0; i < 10; i++){ printf("%d ", *arr[i]); //returning memory to system free(arr[i]); } printf("\n"); return 0; } The above code will produce the following output...

January 2, 2015 · 1 min · Zeeshan Khan