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

Discussion Forum : Object Oriented Programming Using C++ - Section 1 (Q.No. 10)
10.
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?
char function(double d, char c)
int function(int d, char c)
both (a) and (b)
neither (a) nor (b)
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
12 comments Page 1 of 2.

Himanshu said:   1 decade ago
Please give a example of the same.

Ajit said:   1 decade ago
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:   1 decade ago
Its just like function overloading.

Rohit said:   1 decade ago
Double can take 4 byte, but int can take only 2 byte.

Surendranath reddy said:   1 decade ago
Yes, I agree to what ajith said.

Pinky said:   1 decade ago
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:   10 years ago
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:   10 years ago
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).
(1)

Yasvanth said:   9 years ago
In function overloading concept the function name is same but the parameters passing through it are different.
(1)

Qama Balti said:   9 years ago
I think here is the case of overriding not overloading guys.

Because in overriding type f.name and parameter should be same.


Post your comments here:

Your comments will be displayed after verification.