Function overloading in cpp

Function overloading


C++ program for function overloading.Function overloading means two or more functions can have the same name but either the number of arguments or the data type of arguments has to be different. Return type has no role because the function will return a value when it is called and at compile time compiler will not be able to determine which function to call.
Function overloading is also known as compile time polymorphism.



#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 x) {
    cout << "Integer number: " << x << endl;
}

void display(float x) {
    cout << "Float number: " << x << endl;
}

void display(int x1, float x2) {
    cout << "Integer number: " << x1;
    cout << " \nfloat number:" << x2;
}


output:
Integer number: 5
Float number: 5.5
Integer number: 5
float number:5.5
Process returned 0 (0x0)   execution time : 0.300 s









Comments

Popular posts from this blog

C program that contains a string XOR each character in this string with 0 ,127

Queue in Data Structure(DS)

Implementation of stack Using Array