Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Interview Subjective Questions on C++

Home » C++ » Interview Questions on C++



Q 23: What if I can't wrap the local in an artificial block?
Show Ans

Q 24: But can I explicitly call a destructor if I've allocated my object with new?
Show Ans

Q 25: What is "placement new" and why would I use it?
Show Ans

Q 26: When I write a destructor, do I need to explicitly call the destructors for my member objects?
Show Ans

Q 27: When I write a derived class's destructor, do I need to explicitly call the destructor for my base class?
Show Ans

Q 28: Is there any difference between List x; and List x();?
Show Ans

Q 29: Can one constructor of a class call another constructor of the same class to initialize the this object?
Show Ans

Q 30: Is the default constructor for Fred always Fred::Fred()?
Show Ans

Q 31: Which constructor gets called when I create an array of Fred objects?
Show Ans

Q 32: Should my constructors use "initialization lists" or "assignment"?
Show Ans

Q 33: Should you use the this pointer in the constructor?
Show Ans

Q 34: What is the "Named Constructor Idiom"?
Show Ans

Q 35: What is virtual function?
Show Ans

Q 36: What is a "pure virtual" member function?
Show Ans

Q 37: How virtual functions are implemented C++?
Show Ans

Q 38: What is pure virtual function? or what is abstract class?
Show Ans

Q 39: What is Pure Virtual Function? Why and when it is used?
Show Ans

Q 40: How Virtual functions call up is maintained?
Show Ans

Q 41: What is a virtual destructor?
Show Ans

Q 42: What is a class?
Show Ans

Q 43: What are the differences between a C++ struct and C++ class?
Show Ans

Q 44: How do you know that your class needs a virtual destructor?
Show Ans

Q 45: What is encapsulation?
Show Ans

Q 46: What is "this" pointer?
Show Ans

Q 47: What happens when you make call "delete this;"?
Show Ans

Q 48: What is assignment operator?
Show Ans

Q 49: What are all the implicit member functions of the class? Or what are all the functions which compiler implements for us if we don't define one?
Show Ans

Q 50: What is a container class? What are the types of container classes?
Show Ans

Q 51: What is Overriding?
Show Ans

Q 52: How do you access the static member of a class?
Show Ans

Q 53: What is a nested class? Why can it be useful?
Show Ans

Q 54: What is a local class? Why can it be useful?
Show Ans

Q 55: What a derived class can add?
Show Ans

Q 56: What happens when a derived-class object is created and destroyed?
Show Ans

Q 57: How do I create a subscript operator for a Matrix class?
Show Ans

Q 58: Why shouldn't my Matrix class's interface look like an array-of-array?
Show Ans

Q 59: Should I design my classes from the outside (interfaces first) or from the inside (data first)?
Show Ans

Q 60: Is there a way to force new to allocate memory from a specific memory area?
Show Ans

Q 61: How does free know the size of memory to be deleted.?
Show Ans

Q 62: How do I allocate multidimensional arrays using new?
Show Ans

Q 63: Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?
Show Ans

Q 64: Why should I use new instead of trustworthy old malloc()?
Show Ans

Q 65: Can I use realloc() on pointers allocated via new?
Show Ans

Q 66: Do I need to check for NULL after p = new Fred()?
Show Ans

Q 67: How can I convince my (older) compiler to automatically check new to see if it returns NULL?
Show Ans

Q 68: Do I need to check for NULL before delete p?
Show Ans

Q 69: What are the two steps that happen when I say delete p?
Show Ans

Q 70: In p = new Fred(), does the Fred memory "leak" if the Fred constructor throws an exception?
Show Ans

Q 71: How do I allocate / unallocate an array of things?
Show Ans

Q 72: What if I forget the [] when deleteing array allocated via new T[n]?
Show Ans

Q 73: Can I drop the [] when deleteing array of some built-in type (char, int, etc)?
Show Ans

Q 74: After p = new Fred[n], how does the compiler know there are n objects to be destructed during delete[] p?
Show Ans

Q 75: Is it legal (and moral) for a member function to say delete this?
Show Ans

Q 76: How do I throw polymorphically?
Show Ans

Q 77: When I throw this object, how many times will it be copied?
Show Ans

Q 78: But MFC seems to encourage the use of catch-by-pointer; should I do the same?
Show Ans

Q 79: What are some ways try / catch / throw can improve software quality?
Show Ans

Q 80: What should I throw? Show Ans

Q 81: What should I catch? Show Ans

Q 82: What issue do auto_ptr objects address?
Show Ans

Q 83: What is a smart pointer?
Show Ans

Q 84: Is there any problem with the following : char*a=NULL; char& p = *a;?
Show Ans

Q 85: What is the difference between a pointer and a reference?
Show Ans

Q 86: What is the difference between const char *myPointer and char *const myPointer?
Show Ans

Q 87: When should I use references, and when should I use pointers?
Show Ans

Q 88: How do I convert an integer to a string?
Show Ans

Q 89: How do you link a C++ program to C functions?
Show Ans

Q 90: Is there anything you can do in C++ that you cannot do in C?
Show Ans

Q 91: What are the differences between a struct in C and in C++?
Show Ans

Q 92: What does extern "C" int func(int *, Foo) accomplish?
Show Ans

Q 93: What are the access privileges in C++? What is the default access level?
Show Ans

Q 94: How does C++ help with the tradeoff of safety vs. usability?
Show Ans

Q 95: What are the benefits of operator overloading?
Show Ans

Q 96: What are some examples of operator overloading?
Show Ans

Q 97: But operator overloading makes my class look ugly; isn't it supposed to make my code clearer?
Show Ans

Q 98: What operators can/cannot be overloaded?
Show Ans

Q 99: Can I overload operator== so it lets me compare two char[] using a string comparison?
Show Ans

Q 101: Can I create a operator** for "to-the-power-of" operations?
Show Ans

Q 102: Okay, that tells me the operators I can override; which operators should I override?
Show Ans

Q 103: What are some guidelines / "rules of thumb" for overloading operators?
Show Ans

Q 104: Implement Binary Search Tree in C++?
Show Ans

Q 105: What does it mean that "friendship isn't inherited, transitive, or reciprocal"?
Show Ans

Q 106: Should my class declare a member function or a friend function?
Show Ans

Q 107: How can I provide printing for my class Fred?
Show Ans

Q 108: But shouldn't I always use a printOn() method rather than a friend function?
Show Ans

Q 109: How can I provide input for my class Fred?
Show Ans

Q 110: How can I provide printing for an entire hierarchy of classes?
Show Ans

Q 111: Should I use NULL or 0?
Show Ans

Q 112: Can inline functions have a recursion?
Show Ans

Q 113: Explain the scope resolution operator?
Show Ans

Q 114: Write a function to display an integer in a binary format. Show Ans

Q 115: How many ways are there to initialize an int with a constant?
Show Ans

Q 116: What is your reaction to this line of code? delete this; Show Ans

Q 117: What are the debugging methods you use when came across a problem?
Show Ans

Q 118: How the compiler arranges the various sections in the executable image?
Show Ans

Q 119: Can you think of a situation where your program would crash without reaching the breakball, which you set at the beginning of main()?
Show Ans

Q 120: Why do C++ compilers need name mangling?
Show Ans

Q 121: What is difference between template and macro?
Show Ans

Q 122: What are C++ storage classes?
Show Ans

Q 123: What are storage qualifiers in C++ ?
Show Ans

Q 124: What is reference ??
Show Ans

Q 125: What is passing by reference?
Show Ans

Q 126: When do use "const" reference arguments in function?
Show Ans

Q 127: When are temporary variables created by C++ compiler?
Show Ans

Q 128: What problem does the namespace feature solve?
Show Ans

Q 129: What is the use of 'using' declaration?
Show Ans

Q 130: What is an Iterator class?
Show Ans

Q 131: What do you mean by Stack unwinding?
Show Ans

Q 132: Implementation of string length using pointer hopping Show Ans

Q 133: What is inline function?
Show Ans

Q 134: What is name mangling in C++??
Show Ans

Q 135: Can you think of a situation where your program would crash without reaching the breakpoint which you set at the beginning of main()?
Show Ans

Q 136: What does it mean to declare a... (a) member function as virtual? (b) member variable as static? (c) function as static? (d) destructor as static? Show Ans

Q 137: What is faster ++i or i++, where i is an interger variable? Show Ans

Q 138: Find the size of an interger data type with out using sizeof() function?
Show Ans

Q 139: How can I make it so keys pressed by users are not echoed on the screen?
Show Ans

Q 140: Why can't I open a file in a different directory such as "..\test.dat"?
Show Ans

Q 141: How can I open a stream in binary mode?
Show Ans

Q 142: How can I "reopen" std::cin and std::cout in binary mode?
Show Ans