Computer Science - Object Oriented Programming Using C++ - Discussion


A C++ program contains a function with the header int function(double d, char c). Which of the following function headers could be used within the same program?

[A]. char function(double d, char c)
[B]. int function(int d, char c)
[C]. both (a) and (b)
[D]. neither (a) nor (b)

Answer: Option B


No answer description available for this question.

Himanshu said: (Mar 15, 2011)  
Please give a example of the same.

Ajit said: (Jul 3, 2011)  
The right answer here should be (B). As the compiler differentiates the functions with same name based on.

I) No.of arguments.

II) Type of arguments.

The return type is not a taken into account in case of function overloading.

Thus (A) is ruled out.

Gautam said: (Oct 7, 2011)  
Its just like function overloading.

Rohit said: (Dec 9, 2011)  
Double can take 4 byte, but int can take only 2 byte.

Surendranath Reddy said: (Jan 22, 2012)  
Yes, I agree to what ajith said.

Pinky said: (Oct 12, 2013)  
Because function overloading is according to the change in parameter not in return type., here char function() contain same data type so it is not accepted.

Manash E B K said: (Dec 4, 2015)  
In function overloading function names are same for different functions but all these same named function should have different arguments and type of arguments and return type should be same. That's why answer is B.

Deb said: (Jan 19, 2016)  
It uses the concept of function overloading which states that there could be multiple no. of functions with the same name, but the signature list must be different (the no. of and type of parameters).

Yasvanth said: (Apr 4, 2016)  
In function overloading concept the function name is same but the parameters passing through it are different.

Qama Balti said: (Dec 12, 2016)  
I think here is the case of overriding not overloading guys.

Because in overriding type and parameter should be same.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.