Join our subscribers list to get the latest news, updates and special offers directly in your inbox
Overview
Dynamic Memory allocations in C with code
Dynamic memory allocation in C is the process of allocating memory during runtime, rather than at compile-time, which is known as static memory allocation. Unlike static memory allocation, dynamic memory allocation enables programs to allocate memory on demand during program execution, rather than reserving a fixed amount of memory at the beginning of the program.
In C, dynamic memory allocation is accomplished with the help of four functions, namely malloc(), calloc(), realloc(), and free(). These functions are part of the standard library (stdlib.h) and are used to allocate and deallocate memory during program runtime. With dynamic memory allocation, a program can obtain the memory it needs at runtime rather than allocating a fixed amount of memory at compile time.
Classification on the basis of functions
In this program, we have first allocated memory using malloc() function for an integer array of size 5. We have then initialized the array with values 1 to 5 and printed them. Finally, we have freed the memory using free() function.
EmbeddedWala
EmbeddedWala Apr 27, 2023 0 19.3K
EmbeddedWala Jun 14, 2023 0 19.2K
EmbeddedWala Apr 26, 2023 0 17.3K
EmbeddedWala Aug 30, 2022 0 15.3K
EmbeddedWala Apr 27, 2023 0 15.3K
EmbeddedWala Jun 19, 2022 0 4.5K
This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies Find out more here