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?
Discussion:
12 comments Page 1 of 2.
Nishtha said:
1 year ago
But the return type is different in A) then it cannot say overloaded.
Can anyone clarify it to me?
Can anyone clarify it to me?
Rohit Raj said:
1 year ago
@All.
In C++, function overloading allows multiple functions with the same name but different parameter lists.
For the given function header `int function(double d, char c)`, here are some examples of function headers that could be used within the same program:
1. `int function(double d, char c);` (Same as the original)
2. `int function(int i, char c);` (Different parameter type for the first argument)
3. `double function(double d, char c, int i);` (Additional parameter)
4. `int function(char c, double d);` (Different order of parameters)
5. `int function(double d);` (Different number of parameters)
These are just a few examples, and there are more possibilities depending on the types and number of parameters you want to use. Ensure that the function headers differ in terms of the number or types of parameters to avoid ambiguity.
In C++, function overloading allows multiple functions with the same name but different parameter lists.
For the given function header `int function(double d, char c)`, here are some examples of function headers that could be used within the same program:
1. `int function(double d, char c);` (Same as the original)
2. `int function(int i, char c);` (Different parameter type for the first argument)
3. `double function(double d, char c, int i);` (Additional parameter)
4. `int function(char c, double d);` (Different order of parameters)
5. `int function(double d);` (Different number of parameters)
These are just a few examples, and there are more possibilities depending on the types and number of parameters you want to use. Ensure that the function headers differ in terms of the number or types of parameters to avoid ambiguity.
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.
Because in overriding type f.name and parameter should be same.
Yasvanth said:
9 years ago
In function overloading concept the function name is same but the parameters passing through it are different.
(1)
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)
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.
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.
Surendranath reddy said:
1 decade ago
Yes, I agree to what ajith said.
Rohit said:
1 decade ago
Double can take 4 byte, but int can take only 2 byte.
Gautam said:
1 decade ago
Its just like function overloading.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers