Function Overloading

Demonstrates how to create multiple functions with the same name but different parameters.

cppCopy code#include <iostream>

void print(int i) {
    std::cout << "Integer: " << i << std::endl;
}

void print(double d) {
    std::cout << "Double: " << d << std::endl;
}

int main() {
    print(5);      // Calls print(int)
    print(5.5);    // Calls print(double)
    return 0;
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *