1. Which of the followings is/are not false about friend function ?

1. It can be called / invoked with class object
2. It has objects as arguments
3. It can have built-in types as arguments
4. It must declared only in public part of a class
5. It does not have this pointer as an argument

a. Only 2,4
b. Only 1,2,5
c. Only 2,3,5
d. All of these

c. Only 2,3,5

2. Default values for a function are need to be specified from left to right only.

a. True
b. False

b. False
Default values need to be specified from Right to Left order.
Example:
void calculate(int amt, int years, float rate=7.8); //valid
void calculate(int amt, int years=5, float rate=7.8); //valid
void calculate(int amt=21000, int years, float rate=7.8); //Invalid
Third statement is invalid as we skipped second parameter of the function. Rule says that default values should be set from Right to Left order only. We cannot provide a default value to

specific parameter in the middle of an parameter list.

3. If a program uses Inline Function, then the function is expanded inline at ___________.

a. Compile time
b. Run time
c. Both a and b
d. None of these

b. Run time

4. A const object of a class can call non-const member function of the class.

a. True
b. False

b. False

5. Can we alter/modify the values of data members of a class inside const member function?

a. Yes
b. No.

a. Yes

6. Const member function does not allow to modify/alter value of any data member of the class.

a. True
b. False

a. True

7. Can member functions of one class be friend functions of another class?

a. Yes
b. No

a. Yes

8. A function can be declared as friend maximum only in two classes.

a. True
b. False

b. False

9. A friend function does not have this pointer associated with it.

a. True
b. False

a. True

10. Function overloading can also be achieved if two or more functions differ only in their return types.

a. True
b. False

b. False

Download Interview PDF

11. In any ways, Non-member function cannot have access to the private data of the class.

a. True
b. False

b. False

12. If an argument to a function is declared as const, then

a. function can modify the argument
b. Function can't modify the argument
c. const argument to a function is not possible
d. None of these

b. Function can't modify the argument

13. Assigning one or more function body to the same name is called_______________

a. Function Overriding
b. Function Overloading
c. Both a and b
d. None

b. Function Overloading

14. Default values for a function are specified when____

a. function is defined
b. function is declared
c. Both a and b
d. None of these

b. function is declared

15. Inline functions may not work ______.

1. If function contain static variables
2. If function contain global and register variables
3. If function returning value consists looping construct(i.e. for, while)
4. If inline functions are recursive
5. If function contains const value

a. Only 1,4,5
b. Only 2,3,5
c. Only 1,3,4
d. All of these

c. Only 1,3,4

16. By default, if a function with minimum lines of code is declared and defined inside the class becomes Inline function.

a. True
b. False

a. True

17. Default return type of functions in CPP is:

a. void
b. long
c. char
d. int

d. int

18. Do you know private, protected and public access control?

Private
Private is the default access specifier for every declared data item in a class. Private data belongs to the same class in which it is created and can only be used by the other members of the same class.

Protected
When a data item is declared as protected it is only accessible by the derived class member.

Public
Public allows to use the declared data item used by anyone from anywhere in the program. Data items declared in public are open to all and can be accessed by anyone willing to use their values and functions they provide.

19. What is Protected Inheritance?

Public and Protected members are derived as protected members.

20. What is Public Inheritance?

All the public members and protected members are inherited as public and protected respectively.

21. What is Private Inheritance?

The Public and protected members of Base class become private members of the derived class.

22. Explain different access specifiers for the class member in C++?

Access specifiers in C++ determines the scope of the class members.

Public: If a class member is public, it can be used anywhere without the access restrictions.

Private: if a class member is private, it can be used only by the members and friends of class.

Protected: If a class member is protected, it can be used only by the members and friends of class and the members and friends of classes derived from class.

23. Do you know what is the default access level?

The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and its sub- classes. Public members of a class can be accessed by anyone.

24. Explain classes and structure?

Class: User defined data type which contains data and methods to manipulate that data; is known as class. It is the fundamental packaging unit of OO technology. An object is a variable of a Class. Each object is associated with the data of type class with which it is created. Thus we can also say that class is a collection of objects of similar types. It is a user defined data type and behaves like built-in data type of the language. Since class has data and methods to manipulate the data, it supports one of the most important features of OO: Data Encapsulation.

Eg.
class Student
{
int rollno;
int marks1, marks2;
public:
void show(int r); // to print marks
void sum(int r); // to add the marks
};

We can create objects of class using:
class Student s1, s2;

Structure:
A structure is a collection of variables, referenced under one name, providing a convenient means of keeping related information together. Structure declaration forms a template which can be used to create structure objects. The variables inside a structure are called members. Generally all the members of a structure are logically related. Structure declaration precedes the keyword struct.

Consider following example:

struct address
{
char name[80];
char street[80];
char city[20];
char state[20];
};

Please note the semicolon at the end of structure declaration. This is done because a structure declaration is a statement. The type name of this structure is address. We can create structure variables using:

struct address ad1, ad2;
ad1 and ad2 are two variables of the type struct address..

25. Can you please explain the difference between struct and class in terms of Access Modifier?

Classes and structures are syntactically similar. In C++, the role of the structure was expanded, making it an nalternative way to specify a class. In C, the structures include data members, in C++ they are expanded to have function members as well. This makes structures in C++ and classes to be virtually same. The only difference between a C++ struct and a class is that, by default all the struct members are public while by default class members are private.

Download Interview PDF

26. Explain Structure in C++?

A structure is a collection of variables, referenced under one name, providing a convenient means of keeping related information together. Structure declaration forms a template which can be used to create structure objects. The variables inside a structure are called members. Generally all the members of a structure are logically related. Structure declaration precedes the keyword struct.

Consider following example:

struct address
{
char name[80];
char street[80];
char city[20];
char state[20];
};

Please note the semicolon at the end of structure declaration. This is done because a structure declaration is a statement. The type name of this structure is address. We can create structure variables using:

struct address ad1, ad2;
ad1 and ad2 are two variables of the type struct address..

27. Explain Class in C++?

User defined data type which contains data and methods to manipulate that data; is known as class. It is the fundamental packaging unit of OO technology. An object is a variable of a Class. Each object is associated with the data of type class with which it is created. Thus we can also say that class is a collection of objects of similar types. It is a user defined data type and behaves like built-in data type of the language. Since class has data and methods to manipulate the data, it supports one of the most important features of OO: Data Encapsulation.

Eg.
class Student
{
int rollno;
int marks1, marks2;
public:
void show(int r); // to print marks
void sum(int r); // to add the marks
};

We can create objects of class using:
class Student s1, s2;

28. What is the importance of mutable keyword?

Mutable keyword allows assigning values to a data member belonging to a class defined as “Const” or constant.

29. Explain access specifier Public?

If a class member is public, it can be used anywhere without the access restrictions.

30. Explain access specifier protected?

The protected members can be access from member functions of the same class or friend classes or from the members of their immediate derived class.

31. Explain access specifier private?

It is default one and can be access from class member of the same class.