This section contains list of real C++ short interview questions and answers frequently asked in IT industries for freshers and experienced.
Q-Tell me one important properties of “delete” operator except de-allocation of memory.
Answer – “delete” operator calls the destructor of a class.
Q – Can we overload destructor of a class?
Answer– No, we can’t overload the destructor, we don’t have this provision in C++.
Q- In which statement assignment operator will be called?
- A Obj1(5);
- A Obj2(Obj1);
- A Obj2 = Obj1
Answer- None, for every statement copy constructor will get called.
Assignment operator will be called for the following
Obj2 = Obj1; // note this is different than A Obj2= Obj1 as here, we are initializing new object at the time of creation with existing object.
Q- How would you initialize and delete the memory, allocated using “char* p = new char[length]” by 0, where int length =512;
All the memory slot of characters can be initialized by 0 using function “memset()”
Since, this is the array of characters, it should be de-allocated using
Q-Can we create array of references in C++?
Answer – No, We cannot have array of references.