C Programming - Memory Allocation - Discussion

Discussion Forum : Memory Allocation - True / False Questions (Q.No. 2)
2.
malloc() allocates memory from the heap and not from the stack.
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 1 of 2.

Reena said:   1 decade ago
The main difference between stack and heap is, Stack is last in first out. But heap is not related to that that concept. Heap is related to dynamic memory allocation. Heap is the area where the elements are stored in a dma. All the malloc() , realloc() and calloc() are related to dynamic memory alloction concepts.

JITENDRA KUMAR said:   1 decade ago
malloc takes single argument. But calloc function takes two arguments.
malloc initialize memory chunks with garbage value but calloc initialize with zero.

Both are stored in heap memory and allocate memory at dynamic time.
For security purpose malloc is not prefere than calloc.

Bala Aathikesavan said:   2 years ago
Because dynamic memory allocation always takes place in the heap.

Thats why malloc takes place in a heap because malloc comes under the topic of dynamic memory allocation where data will be allocated in heap without any order or randomly.
(1)

Hitesh AGARWAL said:   10 years ago
If Memory is allocating at compile time (static allocation) then stack is use.

But if Memory is allocating at Run time (dynamic allocation) then Heap is use. And malloc is Dynamic allocation so it's clear that it is use heap.

Likita shetty said:   1 decade ago
what is the difference between heap and stack .. i know stack works on the principle of last in first out and what about heap ?

E.senthil kumar.,bca.,(mca) said:   1 decade ago
Stack has some static order, so we can't allocate dynamically, so malloc follow heap.

Saurabh said:   1 decade ago
Heap area consist of hash codes .i.e. addreses while stack may or may not be.

Vaishu said:   1 decade ago
malloc() is dynamic memory allocation. So it is stored in Heep memory.

Amol said:   1 decade ago
What is difference between malloc() & calloc() (4 points)?

Purva said:   1 decade ago
Like stack is First in first out, how does heap work ?


Post your comments here:

Your comments will be displayed after verification.