Advanced C++ Programming Interview Questions and Answers - 1

Question: 1

How are the operators classified?

Operators are classified as



Component Selection,



Member dereferencing,

Memory Management,



Scope Resolution,

Shift and

Type Cast

Question: 2

What is the impact of modifiers?

Unsigned  modifiers the range of the integer values as the sign bit is also used to store data.

Long increases the bytes for a particular data type, thus increasing the range of values.

Question: 3

What do you mean by pure virtual functions?

                           Pure virtual function in object oriented programming is called as virtual method that acts as a function allowing its behavior to be overridden by the class that is inheriting the pure virtual function with the same signature.

                           This is used in case of polymorphism. It is used when a base class is being driven by the derived class and an object of the derived class referred as base or derived class and an object of the derived class referred to base or derived class type.

                            When a derived class overrides the base class method then the output or the behavior will be called as ambiguous. To use the virtual function a virtual keyword is used. This allows the function to be defined in every derived class and use the functionality.


Question: 4

What are the differences between references and pointers?

Both references and pointers can be used to change local variables of one function inside another function. Both of them can also to save copying of big objects when passed as arguments to functions or returned from functions, to get efficiency again.

References are less powerful than pointers

Once a reference is created, it cannot be later made to reference another object; it cannot be reseated. This is often done with pointers.

References cannot be NULL. Pointers are often made NULL to indicate that they are not pointing to any valid thing.

A reference must be initialized when declared. There is no such restriction with pointers.

References are safer and easier to use:

Safer: Since references must be initialized, wild references like wild pointers are unlikely to exist. It is still possible to have references that don’t refer to a valid location.

Easier to use: References don’t need referencing operator to access the value. They can be used like normal variables. ‘&’ operator is needed only at the time of declaration. Also, members of an object reference can be accessed with dot operator (‘.’), unlike pointers where arrow operator (->) is needed to access members.

Question: 5

What is encapsulation?

Packaging an object’s variables within its methods is called encapsulation.

Related Questions