Dynamic Memory Allocation in C Programming

# Introduction In C programming, we may not always know the initial size of an array beforehand. In such cases, we use dynamic memory allocation—a method of allocating memory only when necessary. malloc() is a function used in C programming to allocate a specific amount of memory needed for an array or a variable that will be used at run time. In this lab, we will be learning how to allocate memory dynamically using malloc() and then clear out the memory space using free(). > Note: You need to create the file `~/project/main.c` yourself to practice coding and learn how to compile and run it using gcc. ```bash cd ~/project # create main.c touch main.c # compile main.c gcc main.c -o main # run main ./main ```

|60 : 00

Click the virtual machine below to start practicing