0% found this document useful (0 votes)
4 views8 pages

C++ Interview Questions

The document provides a comprehensive list of C++ interview questions and answers covering fundamental concepts such as OOP, inheritance, function overloading, templates, access specifiers, and exception handling. It also includes explanations of key terms like constructors, destructors, and the Standard Template Library (STL). Overall, it serves as a study guide for individuals preparing for C++ interviews.

Uploaded by

vr7240935115
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

C++ Interview Questions

The document provides a comprehensive list of C++ interview questions and answers covering fundamental concepts such as OOP, inheritance, function overloading, templates, access specifiers, and exception handling. It also includes explanations of key terms like constructors, destructors, and the Standard Template Library (STL). Overall, it serves as a study guide for individuals preparing for C++ interviews.

Uploaded by

vr7240935115
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

C++ Interview Questions

1. What is the difference between C and C++?

C is a Procedural Oriented Programming (POP) language, whereas C++ language


supports Object Orientation. Additionally, C++ supports features like templates,
inheritance, function overloading, virtual functions, friend functions, and references.
These features are not supported in C.

2. What does OOPS stand for?

OOPS stands for Object-Oriented Programming System, which is how C++ is


categorized.

3. What is function overloading?

Function overloading is the concept of having many functions with the same name.
These functions should have different parameters for different types of functioning.

4. What is operator overloading?

Manipulating the operations of a pre-existing operator to achieve different operations.

5. What is a class in C++?

A class is a collection of different variables and different functions. The variables are
called data members and the functions are called member functions.

6.What is a Friend Class?

If a class is mentioned as a friend class to another class, then it can access private and
protected members of the other class.

Example:

class ClassA

private:

int a;

public:
ClassA()

a=10;

friend class FriendClass;

};

class FriendClass

private:

int b;

public:

void printClassA(ClassA& p)

cout<<“a=”<<p.a<<endl;

};

int main()

ClassA x;

FriendClass y;

y.printClassA();

return 0;

}
7. How can we access data members and member functions of a class?

Dot-Operator( . ) helps to access data members and member functions of a class.

8. What is inheritance?

Inheritance is the feature in which an object acquires the properties of another class.

9. What are the different types of inheritances?

There are different types of Inheritances-

• Single inheritance
• Multiple inheritance
• Multi-level inheritance
• Hierarchical inheritance
• Hybrid inheritance

10. What is single inheritance?

In Single Inheritance, there is one derived class and one base class.

11. What is multilevel inheritance?

In multi-level inheritance, a class is derived from another derived class.

12. What is multiple inheritance?

This is when a class can be derived with more than one parent class.

13. What is hierarchical inheritance?

In hierarchical inheritance, many classes are derived from a single parent class.

14. What is Hybrid Inheritance?

This is a combination of more than one inheritance, called hybrid inheritance. It is also
called virtual inheritance.

15. What is Template?

A template is a method for creating generic classes and generic functions.

16. What are access specifiers? What are the different types?
Access Specifiers define the accessibility of the members of the class. There are three
types of access specifiers:

1. Private – they are only accessible from inside of the class


2. Protected – like private specifiers but with an extra feature — they are also
accessible in derived classes
3. Public – they are accessible from both inside and outside the class

17. What is a friend function?

A friend function to a class has access to all the members of the class, even the private
ones. We declare it outside the class.

18. What is a virtual function?

A virtual function is a function declared as a member function of a class, but its


definition is inside its derived class.

19. What is data hiding?

Data hiding is hiding data in objects. This is generally done by having private data
members of the class.

20. What is a constructor?

A constructor is a special member function of a class. When we declare an object, it


initializes the data member.

21. What is a Copy Constructor?

A Copy Constructor is a member function of a class. When called while creating a new
object of the class, it initializes the object using another object of the same class. In
order to use a Copy Constructor, there should be already an existing object of that
class.

Example:

class Copy

private:

int a;
public:

Copy(int z)

a=z;

Copy( Copy &x)

a=x.a;

void print()

cout<<“Value of ‘a’ is ”<<a<<endl;

};

int main()

Copy p(10);

p.print();

Copy q = p;

q.print();

22.What is the use of Static Member Functions?


If you make a member function of a class static, you make it independent of any object
of the class. Function Calls of a static member function can be made even if there
doesn’t exist any object of that class.

23. In how many ways is scope resolution used?

There are many ways to use scope resolution. Some use examples include:

• To define a member function outside the class


• To access data members of various classes while in inheritance

24. What are inline functions?

If a function is inline, the compiler places a copy of the code of that function at each
point where the function is called at compile time.

25. State the advantage of inline functions.

The inline functions increase the execution time of the program.

26. What is the difference between structure and class?

The variables of the structures are public, whereas the data member of the class can be
made as private.

27.What is the difference between a Local and a Global Variable?

A variable, when declared inside a code block, is called a local variable. We can use this
Local Variable only inside the code block. A global variable is declared on the top of the
program, before all the function definitions. It can be accessed from anywhere in the
code.

28.What is Compilation Time and Run Time?

The time Compiler takes for compiling a piece of code is called Compilation Time of the
code. The time taken by the program to run is called Run Time.

29.What is an Assignment Operator?

We use Assignment Operator for assigning value to a variable. It is denoted by ‘=’.

30. What is function overriding?


Re-defining the member function of base class in the derived class is function
overriding.

31. Explain polymorphism.

If an object follows polymorphism, then it acts differently in different conditions. There


are two types of polymorphism:

1. Compile-time polymorphism (static binding)


2. Run-time polymorphism (dynamic binding)

32. What is inner class?

A nested class is a class which is declared inside another class.

33. Explain exception handling.

Exception handling is used when some exception is encountered in the program. Three
keywords are used for exception handling: try, catch, throw.

34. What is a destructor?

A destructor is a special member function. The Destructor destructs the object and
frees up space.

35. What is the use of a virtual destructor?

When we try to delete an object of the derived class using a base class pointer, some
undefined is encountered. To prevent this, a virtual destructor should be defined in the
base class.

36. What is the full form of STL?

STL stands for Standard Template Library.

37. Can we store duplicate values in a set?

No, we cannot store duplicate values in a set.

38. What type of data structure does map use?

Map uses BST as its data structure.

39. Can we initialize a vector with an array?


Yes, we can initialize a vector with an array.

40. What are some components of STL?

Some of the components of STL are iterators, containers, and algorithms.

You might also like