Q) True and false about inline function statements in C++
class A{
public:
void func1(){
}
void func2();
};
inline void A::func2(){
}
- Func1 is inline function
- Func2 only is inline function
- Func1 and Func2 both are inline functions
- None of the above is inline
Answer: 3
Q) Which function can be called without using an object of a class in C++
- Virtual function
- Inline function
- Static function
- constant function
Answer: 3
Q) Which of the following function declaration using default arguments is correct?
- int foo(int x, int y =5, int z=10)
- int foo(int x=5, int y =10, int z)
- int foo(int x=5, int y, int z=10)
- all are correct
Answer: 1
Explanation: Default arguments in a function in C++ program is initialized from right to left.
Q) Which function cannot be overloaded in C++ program?
- Virtual function
- member function
- Static function
- All can be overloaded
Answer: 3
Static functions cannot be overloaded in C++ programming. You can read static function in C++ and how it differs from C language.
Q) Choose the correct answer for following piece of C++ pseudo code
void func(int a, int &b)
{
}
int main(){
int a,b;
func(a,b);
}
- a is pass by value and b is pass by reference
- a is pass by reference and b is pass by value
- a is pass by value and b is pass by address
- a is pass by value and b is pass by pointer
Answer: 1
B parameter is not pass by address/pointer but reference. Here is the correct pseudo code for pass by address or say pointer.
void func(int a, int *b)
{
}
int main(){
int a,b;
func(a,&b);
}
Read about difference between pointer and reference in C++