Commonly Asked C++ Programming Interview Questions | Set 10
91. What are the few advantages of Inline function?
Ans: 1) It offers an improved macro facility.
2) By using the inline functions, the user can split a large function with many nested modules of statement blocks into many small inline functions.
92. What is a scope resolution operator?
Ans: The scope resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
93. What is the difference between Object and Instance?
Ans: 1) An instance of a user-defined type is called an object. We can instantiate many objects from one class.
2) An object is an instance of a class.
94. What is the difference between declaration and definition of a variable?
Ans: The declaration is specifying the data type of a particular variable and its name. The declaration tells the compiler to hold space for a variable in the memory based on the data type. The definition of a variable gives value so the linker can link references to the right entities.
95. Can you comment on the scope of a global and local variable?
Ans: The scope of a variable is the area of program code where the variable is active. Local is when it is inside a code block and only active and accessible there. Global means the variable is accessible throughout the complete program.
96. If you have a global and local variable with the same name, how can you access the global?
Ans: If you have two variables with an identical name but one is local and the other global, the compiler gives precedent to the local one. If you need to access the global variable, then we use a “scope resolution operator (::)”
97. What is inheritance and its types?
Ans: Inheritance is when an object automatically takes on all the properties and behavior of the parent object. There are single, multiple, multilevel, hybrid, and hierarchical inheritance types.
98. What is multiple inheritance?
Ans: Multiple inheritances means that a class that is derived attains or inherits the properties of more than one class and is not limited to two.
99. What is the difference between macro and iniine?
Ans: Inline follows strict parameter type checking, macros do not. Macros are always expanded by preprocessor, whereas compiler may or may not replace the inline definitions.
100. How variable declaration in c++ differs that in c?
Ans: C requires all the variables to be declared at the beginning of a scope but in c++ we can declare variables anywhere in the scope. This makes the programmer easier to understand because the variables are declared in the context of their use.