Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The advantage of using malloc over declaring a variable array for runtime usage is that malloc allows for dynamic memory allocation. This means that the size of the memory block can be determined at runtime, rather than being fixed at compile-time like a variable array. Dynamic memory allocation enables more flexibility in program design by allowing for the allocation and deallocation of memory on-the-fly, which helps reduce memory waste and optimize program performance. Additionally, malloc allows for the allocation of larger memory blocks that may not be possible with variable arrays, which are limited by the available stack space.