0% found this document useful (0 votes)
10 views1 page

12 .DMA - Stack & Heaps

The document discusses dynamic memory allocation. It explains stack allocation is handled by the compiler while the programmer must handle deallocation for heap allocation. The new operator allocates memory while delete deallocates memory by passing the address to the delete function. A dangling pointer occurs when a pointer points to freed memory. Sample questions are provided on dynamically declaring 2D and 3D arrays and multiple choice questions on dynamic memory allocation.

Uploaded by

Himanshu Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

12 .DMA - Stack & Heaps

The document discusses dynamic memory allocation. It explains stack allocation is handled by the compiler while the programmer must handle deallocation for heap allocation. The new operator allocates memory while delete deallocates memory by passing the address to the delete function. A dangling pointer occurs when a pointer points to freed memory. Sample questions are provided on dynamically declaring 2D and 3D arrays and multiple choice questions on dynamic memory allocation.

Uploaded by

Himanshu Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Dynamic Memory Allocation

Stack Memory Allocation


The memory is allocated on the function call stack. The memory gets deallocated
as soon as the function call gets over. Deallocation is handled by the compiler.

Heap Memory Allocation


Allocation takes place on the pile of memory space available to programmers to
allocated and de-allocate. The programmer has to handle the deallocation.
NOTE: ​It is different from the heap data structure.

Delete Operator
To de-allocate a memory p, we pass its address to the delete() function.

New Operator:
New operator is used to allocate a block of memory of the given data type.

Dangling Pointer
If the memory location pointed by the pointer gets freed/ deallocated, then the
pointer is known as the Dangling Pointer.

Practise Question:
1. Declare a 2D array Dynamically.
2. Declare a 3D array Dynamically.
3. MCQs on Dynamic Memory Allocation.

You might also like