+ 5
Why we use malloc () and calloc () in the programs.
C language
6 odpowiedzi
+ 3
They are used to dynamically allocate memory on the heap, which is a much larger memory pool than static allocated memory.
Malloc takes one parameter(size of the memory), allocates it but leaves it uninitialized(garbage values). Calloc takes two arguments (number of blocks to allocate and size of each block), allocates it and initialize all of it to 0.
+ 3
When you write code, try not to leave any space between the malloc/calloc keywords and the parentheses if you want to avoid syntax errors.
0
But we can use malloc/calloc for memory is use to save or memory allocation.
0
But why
0
Because you are not always sure what amount of memory you will use at compile time. Therefore it can be useful to be able to dynamically allocate memory
- 1
Not sure what you mean by that