Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is meant by overloading implements polymorphism?

Answer»

The overloading helps to apply polymorphism because Function overloading means two or more functions having same name but different types of arguments or different number of arguments. Whereas polymorphism refers to one name having many forms of an object behaviour depending on situations.

2.

What are the advantages of inline functions?

Answer»

The advantages of inline functions are:

1. The speed of execution of a program increases.

2. Efficient code can be generated.

3. Readability of the program increases.

3.

Write the advantages of inline functions.

Answer»
  • The speed of execution of a program increases.
  • Efficient code can be generated.
  • Readability of the program increases.
4.

Write any three characteristics of friend function.

Answer»

The characteristics of friend function are:

  • The friend function should not be defined inside the class.
  • It can be declared inside a class under public, private or protected access specifier since it is a non member function and make no difference.
  • A friend function should be defined outside the class without prefix friend.
  • The scope resolution operator should not be used while defining the friends function outside the class since it is not member function of any class.
5.

What are the restrictions on overloaded functions?

Answer»
  • The parameters/arguments should differ in the number of arguments or if they have same number of argument then they should differ in the type of the arguments.
  • The use of typed of keyword for naming functions is not treated as different type but is only a synonym for another type.
6.

When is function overloading needed?

Answer»

Function overloading is normally used when several function of the same name perform identical tasks on different data types.

7.

Write an advantage of function overloading.

Answer»

The overloading function helps to reduce the use of different names for many functions.

8.

Name one condition for overloading of functions.

Answer»

The parameters/arguments should differ in the number of arguments or if they have same number of argument then they should differ in the type of the arguments.

9.

What is an inline function?

Answer»

Inline functions are those functions whose body is inserted in place of the function call.

10.

Write one advantage of inline function.

Answer»

The speed of execution of a program increases.

11.

The inline function is always converted to a code block. True/False.

Answer»

The inline function is always converted to a code block. True 

12.

Explain friend functions and their characteristics.

Answer»

A friend function is a non-member function and is a friend of a class. It is declared inside a class with the prefix friend and defined outside the class like any other normal function without the prefix friend. This friend function can access private and protected data members if it is a friend function of that class.
The characteristics of friend function are:

  • The friend function should not be defined inside the class.
  • It can be declared inside a class under public, private or protected access specifier since it is a non member function and make no difference.
  • A friend function should be defined outside the class without prefix friend
  • The scope resolution operator should not be used while defining the friends function outside the class since it is not member function of any class.
  • It should be called like any other normal function and not to be called using an object with dot operator.
  • The data members of class are accessed through object and dot operator with a data members.
13.

What is a friend function?

Answer»

A friend function is a non-member function and is a friend of a class. It is declared inside a class with the prefix friend and defined outside the class line any other normal function without the prefix friend.

14.

Write any two characteristics of friend function.

Answer»

The characteristics of friend function are:

  • The friend function should not be defined inside the class.
  • It can be declared inside a class under public, private or protected access specifier since it is a non member function and make no difference.
  • A friend function should be defined outside the class without prefix friend.
15.

When are friend functions used? Write syntax for declaration of friend function.

Answer»

A friend function is useful when a function to be shared between the two classes by
making a function as a friend to both the classes, thereby allowing a function to access private and protected data members of both classes.

syntax for declaration of friend function:
class classname {
public:
friend returntype function name (arguments);
}

16.

Can the keyword friend be used while declaring a friend function?

Answer»

Yes, the keyword friend is used while declaring friend function. For example, friend int Avg marks(PUC, cet);

17.

When is it possible that an inline function may not work?

Answer»

The inline function may not work under following situations:

  • The inline function definition is too big or complicated.
  • The inline function is a recursive.
  • The inline function has switch or go to statements.
  • The inline function has while, do-while or for looping controls.
  • The inline function has static variables.
18.

Write the advantages and disadvantages of inline functions.

Answer»

Advantages of inline functions:

  • The speed of execution of a program increases.
  • Efficient code can be generated.
  • Readability of the program increases Disadvantages of inline functions.
  • The size of the executable file increases and more memory is required as the body of inline function is inserted in the place of function call.
  • Not suitable for too long , complicated, recursive function definition.