C++ Programming - Functions - Discussion

Discussion :: Functions - General Questions (Q.No.4)

4. 

Which of the following statement is correct?

[A]. Two functions having same number of argument, order and type of argument can be overloaded if both functions do not have any default argument.
[B]. Overloaded function must have default arguments.
[C]. Overloaded function must have default arguments starting from the left of argument list.
[D]. A function can be overloaded more than once.

Answer: Option D

Explanation:

No answer description available for this question.

Varsharani Buktare said: (Jan 7, 2013)  
Actually , I have one doubt that suppose prototype of some overloaded functions.

void addition(int a,int b,int c=3, int d=4);
void addition(int,int);

& In our program we write the function call like:

additon(1,2,3,2);
addition(6,7,8);
addition(5,1); // Which function going to call the compiler here?
Or compiler get the ambiguity?
What happens exactly?

Satya said: (Aug 31, 2013)  
void addition(int a,int b,int c=3, int d=4);
void addition(int,int); Not allowed by the compiler.

Why do you need the above two functions when all your commands can be executed by the first function that is

void addition(int a,int b,int c=3, int d=4);

This can execute all the below calls.
additon(1,2,3,2);
addition(6,7,8);
addition(5,1);

Asd said: (Mar 26, 2015)  
Why A is not true? We can overload by using const!

Hrudwik said: (Jun 7, 2016)  
Since using const, it must have a default argument. Which against option A.

Hope this helps.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.