Skip to content

Tag Archives: new and delete

Need for deletion of the object: To avoid memory leak as when an object is created dynamically using new, it occupies memory in the Heap… Read More
In this article, we will discuss the Dynamic initialization of objects using Dynamic Constructors.  Dynamic initialization of object refers to initializing the objects at a… Read More
As we know that new is used to create memory dynamically and it is the programmer’s responsibility to delete the memory location explicitly and it… Read More
Is it fine to call delete twice for a pointer? #include<iostream> using namespace std;    int main() {     int *ptr = new int;     delete ptr;… Read More
What happens when delete is used for a NULL pointer? int *ptr = NULL; delete ptr;  (A) Compiler Error (B) Run-time Crash (C) No Effect… Read More
Predict the output? #include <iostream> using namespace std;    class Test  {   int x;   Test() { x = 5;} };    int main() {    Test… Read More
Which of the following is true about new when compared with malloc. 1) new is an operator, malloc is a function 2) new calls constructor,… Read More
How to create a dynamic array of pointers (to integers) of size 10 using new in C++? Hint: We can create a non-dynamic array using… Read More