C++ Programming - Functions - Discussion

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

3. 

Which of the following statement is correct?

[A]. Overloaded functions can have at most one default argument.
[B]. An overloaded function cannot have default argument.
[C]. All arguments of an overloaded function can be default.
[D]. A function if overloaded more than once cannot have default argument.

Answer: Option C

Explanation:

No answer description available for this question.

Sasi said: (Jun 7, 2012)  
the parameters will be changed but not the functionality and the arguments in the function .

Abin said: (Sep 8, 2012)  
Option c is correct. It is not a matter weather the parameter is default or not!

Aditi said: (Jun 4, 2013)  
The trailing arguments of the function can have default arguments.

Shalin said: (Jun 30, 2013)  
But say there are 2 functions one has one argument and other has 2 arguments and if I keep parameters blank while calling this function which one should be called as default arguments are defined in both of them?

Joel said: (Sep 14, 2013)  
include<stdio.h>
int main ()
{
int a;
int b;
printf("please enter the number a&b");
scanf(%d,%d:&a and &b);

return0;

}

Seema said: (Sep 26, 2013)  
void fun(int a=10,int b=20);

void fun();

main()
{
fun();
}

Which function will be called in main() first or second?

Pankaj Sharma said: (Oct 3, 2013)  
void fun(int a=10,int b=20);
void fun();
main()
{
fun();
}

Ambiguous situation so error.

Kapil Makwana said: (Mar 13, 2014)  
void fun(int a=10,int b=20);

void fun();

main()
{
fun();
}

Which function will be called in main() first or second?

Sonu Rajpoot said: (Jul 16, 2014)  
void fun(int a=10,int b=20);

void fun();

main()
{
fun();
}

Error would occur.

Smruti Mishra said: (Jul 31, 2014)  
void fun(int a=10,int b=20);
void fun();
main()
{
fun();
}

Error will occur because redeclaration of function is type mismatch.

Purvi said: (Aug 28, 2016)  
That means the answer is incorrect, because when we call the function, it is differentiated by the different argument type, that is only overloading.

Can someone give a reason?

Pradhnya said: (Oct 2, 2016)  
I think option B is the correct answer.

Pradnya said: (Oct 8, 2016)  
@Pradhnya.

Only option c is correct answer because it says//*All arguments of an overloaded function "CAN BE " default*// means that It does not matter weather the parameter is default or not.

Vignesh Mahendran said: (Dec 19, 2017)  
void fun(int a=10,int b=20);
void fun();
main()
{
fun();
}

So, error will occur.

Priya said: (Nov 15, 2018)  
I think that option B is correct because the overloaded function should be varied in type and number of argument, in that case, if we declare a function with default argument, the compiler gets confused to execute the correct function.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.