Top C-plus-plus Interview Questions
Mobiprep handbooks are free downloadable placement preparation resources that can help you ace any company placement process. We have curated a list of the 40 most important MCQ questions which are asked in most companies such as Infosys, TCS, Wipro, Accenture, etc. The placement handbooks also have detailed explanations for every question ensuring you revise all the questions with detailed answers and explanations.
Question
21
Explanation
Differentiate between structure and classes.
1) In structure have a by default public. In class have a by default private.
2) There is no data hiding features comes with structures. Classes do, private, protected and public.
3) A structure can't be abstract, a class can.
4) Structure are value type, They are stored as a stack on memory. where as class are reference type. They are stored as heap on memory.
Question
22
Explanation
What are the advantages and disadvantages of passing values by reference in a function?
Advantages of passing by reference:
> It allows a function to change the value of the argument, which is sometimes useful.
> Because a copy of the argument is not made, it is fast, even when used with large structs or classes.
> References can be used to return multiple values from a function.
> References must be initialized, so there’s no worry about null values
.
Disadvantages of passing by reference:
> Because a non-const reference cannot be made to an rvalue (e.g. a literal or an expression), reference arguments must be normal variables.
> It can be hard to tell whether a parameter passed by nonconst reference is meant to be input, output, or both.
> It’s impossible to tell from the function call whether the argument may change. An argument passed by value and passed by reference looks the same.
Question
23
Explanation
List and explain access specifiers in C++.
Access specifiers indicate accessibility of member of class. It can be private , public or protected.
Private:-
Private keyword, means that no one can access the class members declared private outside that class. If someone tries to access the private member, they will get a compile time error. By default class variables and member functions are private.
Public:-
Public, means all the class members declared under public will be available to everyone. The data members and member functions declared public can be accessed by other classes too. Hence there are chances that they might change them. So the key
members must not be declared public. \
Protected:-
Protected, is the last access specifier, and it is similar to private, it makes class member inaccessible outside the class. But they can be accessed by any subclass of that class.
Question
24
Explanation
What are the conditions where inline functions cannot be extended?
The conditions where inline functions cannot be expanded are:
1) For functions returning values, if a loop, a switch or goto exists.
2) For functions not returning values, if a return statement exists.
3) If functions contain static variables.
4) If inline functions are recursive.



.png)