Q) True and false about inline function statements in C++
class A{
public:
	void func1(){
	}
	void func2();
};
inline void A::func2(){
	
}
  1. Func1 is inline function
  2. Func2 only is inline function
  3. Func1 and Func2 both are inline functions
  4. None of the above is inline

Answer: 3


Q) Which function can be called without using an object of a class in C++
  1. Virtual function
  2. Inline function
  3. Static function
  4. constant function

Answer: 3


Q) Which of the following function declaration using default arguments is correct?
  1. int foo(int x, int y =5, int z=10)
  2. int foo(int x=5, int y =10, int z)
  3. int foo(int x=5, int y, int z=10)
  4. 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?
  1. Virtual function
  2. member function
  3. Static function
  4. 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);
}

  1. a is pass by value and b is pass by reference
  2. a is pass by reference and b is pass by value
  3. a is pass by value and b is pass by address
  4. 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++


Related Posts