w3resource

C++ Dynamic Memory Allocation Exercises with Solutions

C++ Dynamic Memory Allocation [ 10 exercises with solution ]

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

1. 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. Write a C++ program to dynamically allocate an array of integers and strings and initialize its elements.

Click me to see the solution

3. 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. 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. Write a C++ program to dynamically create an object of a class using the new operator.

Click me to see the solution

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

Click me to see the solution

7. 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. 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. 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. 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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/cpp-exercises/dynamic-memory-allocation/index.php