Skip to content
Related Articles

Related Articles

C++ | Function Overloading and Default Arguments | Question 2
  • Last Updated : 03 Aug, 2013

Output?




#include<iostream>
using namespace std;
  
int fun(int x = 0, int y = 0, int z)
return (x + y + z); }
  
int main()
{
   cout << fun(10);
   return 0;
}


(A) 10
(B) 0
(C) 20
(D) Compiler Error


Answer: (D)

Explanation: All default arguments must be the rightmost arguments. The following program works fine and produces 10 as output.

#include <iostream>
using namespace std;

int fun(int x, int y = 0, int z = 0)
{  return (x + y + z); }

int main()
{
   cout << fun(10);
   return 0;
}


Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :