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 2 of 2.
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.
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?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers