In this section, you will learn how to determine the size of a dynamic array in C.
The dynamic array is an array data structure which can be resized during runtime which means elements can be added and removed. You can see in the given example that we prompt the user to enter the number of elements that he want to set into the array.
The expression (int*)malloc(n*sizeof (int)) stores the number of elements in the memory. The malloc is basically used for memory allocation. By using the for loop the variable i reads the elements from the memory and displays the required array.
Here is the code:
Output will be displayed as:
Posted on: February 5, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles