Computer Science, asked by samar766, 1 year ago

function overloading program

Answers

Answered by kiara124
2
some functions do overload a program and it causes the housing of light solution not overload the program and remove everything which is waist for us


Plz Mark me branliest

kiara124: plz mark me branliest plz
Answered by Anonymous
1
refers to a segment that groups code to perform a specific task.

In C++ programming, two functions can have same name if number and/or type of arguments passed are different.

These functions having different number or type (or both) of parameters are known as overloaded functions. For example:

int test() { } int test(int a) { } float test(double a) { } int test(int a, double b) { }

Here, all 4 functions are overloaded functions because argument(s) passed to these functions are different.

Notice that, the return type of all these 4 functions are not same. Overloaded functions may or may not have different return type but it should have different argument(s).

// Error code int test(int a) { } double test(int b){ }

The number and type of arguments passed to these two functions are same even though the return type is different. Hence, the compiler will throw error.

Example 1: Function Overloading

#include <iostream> using namespace std; void display(int); void display(float); void display(int, float); int main() { int a = 5; float b = 5.5; display(a); display(b); display(a, b); return 0; } void display(int var) { cout << "Integer number: " << var << endl; } void display(float var) { cout << "Float number: " << var << endl; } void display(int var1, float var2) { cout << "Integer number: " << var1; cout << " and float number:" << var2; }

Output

Integer number: 5 Float number: 5.5 Integer number: 5 and float number: 5.5

Here, the display() function is called three times with different type or number of arguments.

The return type of all these functions are same but it's not necessary.

Similar questions