The conversation between human and AI assistant.
How can I create a dynamic array in the programming language C?
Can you explain how to use the malloc function to create a dynamic array?
Of course! The malloc function allocates a block of memory on the heap and returns a pointer to the first byte of the block. You can use this pointer to access the block of memory as an array. Here's an example: int *arr; arr = (int *)malloc(5 * sizeof(int)); This code creates a dynamic integer array with 5 elements.