The Wayback Machine - https://web.archive.org/web/20240213201618/https://www.geeksforgeeks.org/c-this-pointer-question-6/
Open In App
Related Articles

C++ | Function Overloading and Default Arguments | Question 2

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads