C++ | Function Overloading and Default Arguments | Question 5
Output of following program?
#include <iostream> using namespace std; int fun(int=0, int = 0); int main() { cout << fun(5); return 0; } int fun(int x, int y) { return (x+y); } |
chevron_right
filter_none
(A) Compiler Error
(B) 5
(C) 0
(D) 10
Answer: (B)
Explanation: The statement “int fun(int=0, int=0)” is declaration of a function that takes two arguments with default values as 0 and 0.
The last statement is definition of fun().
When we make a call fun(5), x gets the value 5 and y gets 0. So the returned value is 5.
Quiz of this Question
Recommended Posts:
- C++ | Function Overloading and Default Arguments | Question 5
- C++ | Function Overloading and Default Arguments | Question 2
- C++ | Function Overloading and Default Arguments | Question 3
- C++ | Function Overloading and Default Arguments | Question 4
- Default arguments and virtual function
- Templates and Default Arguments
- Some Interesting facts about default arguments in C++
- getopt() function in C to parse command line arguments
- Does C support function overloading?
- Function Overloading and float in C++
- Function overloading and const keyword
- C++ | Operator Overloading | Question 5
- C++ | Operator Overloading | Question 6
- C++ | Operator Overloading | Question 7
- C++ | Operator Overloading | Question 10



