C++ Interview Questions and Answers
Prepare for your Interview today!
Note: Ask the candidate whether the first declaration is pointing to a string or a single character. Both explanations are correct, but if he says that it?s a single character pointer, ask why a whole string is initialized as char* in C++. If he says this is a string declaration, ask him to declare a pointer to a single character. Competent candidates should not have problems pointing out why const char* can be both a character and a string declaration, incompetent ones will come up with invalid reasons.
Note:Anyone confusing assignment and equality operators should be dismissed from the interview. The applicant might make a mistake of passing by value, not by reference. The candidate might also want to return a pointer, not a new object, from the addition operator. Slightly hint that you?d like the value to be changed outside the function, too, in the first case. Ask him whether the statement customer3 = customer1 + customer2 would work in the second case.
#define sq(x) x*x
T *p = new T[10];
delete p;
Everything is correct, Only the first element of the array will be deleted?, The entire array will be deleted, but only the first element destructor will be called.
Yes, the program will crash in an attempt to delete a null pointer.
Most helpful rated by users: