w3resource

C++ Dynamic Memory Allocation Exercises with Solutions


This resource offers a total of 50 C++ Dynamic Memory Allocation problems for practice. It includes 10 main exercises, each accompanied by solutions, detailed explanations, and four related problems.

[An Editor is available at the bottom of the page to write and execute the scripts.]


1. Dynamically Allocate Basic Types

Write a C++ program to dynamically allocate an integer, a character and a string and assign a value to them.

Click me to see the solution


2. Dynamically Allocate an Array of Integers and Strings

Write a C++ program to dynamically allocate an array of integers and strings and initialize its elements.

Click me to see the solution


3. Dynamically Allocate Two Two-Dimensional Arrays of Floating Values and Strings

Write a C++ program to dynamically allocate two two-dimensional arrays of floating values and strings. Initialize its elements.

Click me to see the solution


4. Dynamically Allocate Memory for a Character and a String with User Input

Write a C++ program to dynamically allocate memory for a character and a string. Input a character and a string from the user.

Click me to see the solution


5. Dynamically Create an Object of a Class Using New

Write a C++ program to dynamically create an object of a class using the new operator.

Click me to see the solution


6. Dynamically Create an Array of Objects Using New

Write a C++ program to dynamically create an array of objects using the new operator.

Click me to see the solution


7. Dynamically Allocate Memory for a Structure and Input Its Members

Write a C++ program to dynamically allocate memory for a structure and input its members from the user.

Click me to see the solution


8. Dynamically Allocate Memory for a Linked List and Perform Basic Operations

Write a C++ program to dynamically allocate memory for a linked list and perform basic operations like insert and delete node(s).

Click me to see the solution


9. Dynamically Allocate Memory for a Stack and Implement Push/Pop

Write a C++ program to dynamically allocate memory for a stack data structure. Implement push and pop operations on this stack.

Click me to see the solution


10. Dynamically Allocate Memory for a Queue and Implement Enqueue/Dequeue

Write a C++ program to dynamically allocate memory for a queue data structure. Implement enqueue and dequeue operations on this queue.

Click me to see the solution


CPP Code Editor:



More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.