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 &lt;&lt; "Integer: " &lt;&lt; i &lt;&lt; std::endl;
} void print(double d) {
std::cout &lt;&lt; "Double: " &lt;&lt; d &lt;&lt; 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 *