x

Wednesday, January 27, 2016

Top 99 interview questions and answers for C++| Part 1

Top 99 interview questions and answers for C++| Part 1

These C++ Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of C++.

interview questions and answers for C++

1.

Explain the static member function.

A static member function can be invoked using the class name as it exits before class objects comes into existence. It can access only static members of the class.

2.

What is role of static keyword on class member variable?

A static variable does exit though the objects for the respective class are not created. Static member variable share a common memory across all the objects created for the respective class. A static member variable can be referred using the class name itself.

3.

What is a reference variable in C++?

A reference variable is an alias name for the existing variable. Which mean both the variable name and reference variable point to the same memory location. Therefore updation on the original variable can be achieved using reference variable too.

4.

What is an abstract class in C++?

A class with at least one pure virtual function is called as abstract class. We cannot instantiate an abstract class.

5.

What is a pure virtual function?

A virtual function with no function body and assigned with a value zero is called as pure virtual function.

6.

Distinguish between shallow copy and deep copy.

Shallow copy does memory dumping bit-by-bit from one object to another. Deep copy is copy field by field from object to another. Deep copy is achieved using copy constructor and or overloading assignment operator.

7.

What is the role of mutable storage class specifier?

A constant class object’s member variable can be altered by declaring it using mutable storage class specifier. Applicable only for non-static and non-constant member variable of the class.

8.

Mention the storage classes names in C++.

The following are storage classes supported in C++

auto, static, extern, register and mutable

9.

What is a storage class?

Storage class specifies the life or scope of symbols such as variable or functions.

10.

What is an inline function?

A function prefixed with the keyword inline before the function definition is called as inline function. The inline functions are faster in execution when compared to normal functions as the compiler treats inline functions as macros.

11.

Explain the purpose of the keyword volatile.

Declaring a variable volatile directs the compiler that the variable can be changed externally. Hence avoiding compiler optimization on the variable reference.

12.

What is inheritance?

Inheritance is the process of acquiring the properties of the exiting class into the new class. The existing class is called as base/parent class and the inherited class is called as derived/child class.

13.

What is abstraction?

Abstraction refers to hiding the internal implementation and exhibiting only the necessary details.

14.

What is encapsulation?

The process of binding the data and the functions acting on the data together in an entity (class) called as encapsulation.

15.

What is the role of protected access specifier?

If a class member is protected then it is accessible in the inherited class. However, outside the both the private and protected members are not accessible.

16.

List the types of inheritance supported in C++

Single, Multilevel, Multiple, Hierarchical and Hybrid.

17.

What is an object?

Class is a blue print which reflects the entities attributes and actions. Technically defining a class is designing an user defined data type.

18.

What is a class?

Class is a blue print which reflects the entities attributes and actions. Technically defining a class is designing an user defined data type.

19.

What is the full form of OOPS?

Object Oriented Programming System.

20.

Does C++ supports exception handling? If so what are the keywords involved in achieving the same.

C++ does supports exception handling. try, catch & throw are keyword used for the same.

(more…)

21

What is a copy constructor?

A copy constructor is the constructor which take same class object reference as the parameter. It gets automatically invoked as soon as the object is initialized with another object of the same class at the time of its creation.

22.

What is a friend function?

A function which is not a member of the class but still can access all the member of the class is called so. To make it happen we need to declare within the required class following the keyword ‘friend’.

23.

Can I use ‘delete’ operator to release the memory which was allocated using malloc() function of C language?

No, we need to use free() of C language for the same.

24.

Can I use malloc() function of C language to allocate dynamic memory in C++?

Yes, as C is the subset of C++, we can all the functions of C in C++ too.

25.

What is the purpose of ‘delete’ operator?

‘delete’ operator is used to release the dynamic memory which was created using ‘new’ operator.

26.

Which operator can be used in C++ to allocate dynamic memory?

‘new’ is the operator can be used for the same.

27.

What is a default constructor? Can we provide one for our class?

Every class does have a constructor provided by the compiler if the programmer doesn’t provides one and known as default constructor. A programmer provided constructor with no parameters is called as default constructor. In such case compiler doesn’t provides the constructor.

28.

What is a constructor?

A constructor is the member function of the class which is having the same as the class name and gets executed automatically as soon as the object for the respective class is created.

29.

What is a destructor? Can it be overloaded?

A destructor is the member function of the class which is having the same name as the class name and prefixed with tilde (~) symbol. It gets executed automatically w.r.t the object as soon as the object loses its scope. It cannot be overloaded and the only form is without the parameters.

30.

When a class member is defined outside the class, which operator can be used to associate the function definition to a particular class?

Scope resolution operator (::)

31.

Which access specifier/s can help to achive data hiding in C++?

Private & Protected.

32.

Name the default standard streams in C++.

cin, cout, cerr and clog.

33.

Do we have a String primitive data type in C++?

No, it’s a class from STL (Standard template library).

interviewquiz.net

Leave a Reply

No comments:

Post a Comment