Variable Sized Arrays vs calloc in C

If you declare int array[variable] the memory will be allocated on the stack which is not very good for large, relatively permanent data structures (such as one you might want to return). You don’t need to free memory manually if you use the array syntax since it’s freed when it goes out of scope. calloc on the other hand will allocate memory dynamically at run time on the heap. You’ll have to free it yourself as soon as you’re finished with it.

Leave a Comment