C ++ programming interview questions on pointers, references and memory with answers and explanations. This list contains conceptual and tricky coding / output questions on pointers in c ++. These questions are real programming / quiz asked in software industries to freshers and experienced professionals in technical interviews that we should practice.
Topics – Pointer, Reference, new and delete operator, dynamic memory allocation C++
Q – Find Crash in below C++ program with reason?
Book *b = new Book();
this refers to current class object. Means, if you delete this current class object will be destroyed.
If we call a function using pointer to an object(b->bookInfo();) which is allocated dynamically(Book *b = new Book();), then the object will get destroyed using delete this statement. But,if we call function using statically allocated object then run time error will occur.
Note that delete operator is always applied on dynamically allocated object in C++.