C++ Interview Questions
C++ Coding Interview Questions
1. Design and implement a String class that satisfies the following:
- Supports embedded nulls
- Provide the following methods (at least)
- Constructor
- Destructor
- Copy constructor
- Assignment operator
- Addition operator (concatenation)
- Return character at location
- Return substring at location
- Find substring
- Provide versions of methods for String and for char* arguments
2. Given the following classes
class Fruit {
// …
}
class Apple : public Fruit {
// …
}
class Peach : public Fruit {
// …
}
Advanced C++ and STL Questions I
Q: How do you link a C++ program to C functions?
A: By using the extern “C” linkage specification around the C function declarations.
Q: Explain the scope resolution operator.
A: It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
Q: What are the differences between a C++ struct and C++ class?
A: The default member and base-class access specifiers are different.
Q: How many ways are there to initialize an int with a constant?
A: Two.
Advanced C++ and STL Questions II
Q: What is a virtual destructor?
A: The simple answer is that a virtual destructor is one that is declared with the virtual attribute.
Q: Explain the ISA and HASA class relationships. How would you implement each in a class design?
A: A specialized class “is” a specialization of another class and, therefore, has the ISA relationship with the other class. An Employee ISA Person. This relationship is best implemented with inheritance. Employee is derived from Person. A class may have an instance of another class. For example, an employee “has” a salary, therefore the Employee class has the HASA relationship with the Salary class. This relationship is best implemented by embedding an object of the Salary class in the Employee class.
C++ on Unix
What is a Make file?(Fujitsu)
Make file is a utility in Unix to help compile large programs. It helps by only compiling the portion of the program that has been change
What is deadlock? (Novell)
Deadlock is a situation when two or more processes prevent each other from running.Example: if T1 is holding x and waiting for y to be free and T2 holding y and waiting for x to be free deadlock happens.
What is semaphore? (Novell)
Semaphore is a special variable, it has two methods: up and down. Semaphore performs atomic operations, which means ones a semaphore is called it can not be inturrupted.
C & C++ Questions for Interviews
- What is the output of printf(”%d”)
- What will happen if I say delete this
- Difference between “C structure” and “C++ structure”.
- Diffrence between a “assignment operator” and a “copy constructor”
- What is the difference between “overloading” and “overridding”?
- Explain the need for “Virtual Destructor”.
- Can we have “Virtual Constructors”?
- What are the different types of polymorphism?
- What are Virtual Functions? How to implement virtual functions in “C”
- What are the different types of Storage classes?
- What is Namespace?
- What are the types of STL containers?.
- Difference between “vector” and “array”?