C++ Interview Question and Answers – Part 3

1. What is the difference between the keywords struct and class in C++?
Answer : By default the members of struct are public and by default the members of the class are private.

2. Explain Call by address and Call by reference
Answer : Call by address: We send address of the actual parameters instead of values. We choose this if we do want the actual parameters to be modified with formal parameters.
Call by reference: The actual parameters are received with the C++ new reference variables as formal parameters. We choose this if we do want the actual parameters to be modified with formal parameters.

3. How can we refer to the global variable if the local and the global variable names are same?
Answer : We can apply scope resolution operator (::) to the for the scope of global variable.

4. What are valid operations on pointers?
Answer : The only two permitted operations on pointers are
Comparision and Addition/Substraction

5. Which function is used to move the stream pointer for the purpose of writing data from stream?
Answer : seekp()

6. Can we create and empty class? If so what would be the size of such object.
Answer : We can create an empty class and the object size will be 1.

7. Define polymorphism?
Answer : Polymorphism means one name, multiple forms. It allows us to have more than one function with the same name in a program.It allows us to have overloading of operators so that an operation can exhibit different behaviours in different instances

8. What is iterator class?
Answer : Iterator class provides an access to the class which are inside the containers(it holds a group of objects in an organized way).
The containers include the data structure, class and abstract data type.

9. What are the types of declarations in C++?
Answer : There are so many types of declaration in C++ are :
Variable declaration
Constant declaration
Function declaration
Object declaration

10. What is scope resolution operator?
Answer : The Scope resolution operator(::) can be used to define the member functions of a program outside the boundary of a class and not within the class specifier.

test1

test1

Comments are closed here.