Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C++ Function Overloading Example (Different Parameters)
✅ C++ Program: Function Overloading with Different Parameters
#include <iostream>
using namespace std;
class Math {
public:
void add(int a, int b) {
cout << "Sum of two ints: " << a + b << "\n";
}
void add(double a, double b) {
cout << "Sum of two doubles: " << a + b << "\n";
}
void add(int a, int b, int c) {
cout << "Sum of three ints: " << a + b + c << "\n";
}
};
int main() {
Math m;
m.add(10, 20); // calls add(int, int)
m.add(5.5, 2.5); // calls add(double, double)
m.add(1, 2, 3); // calls add(int, int, int)
}
๐ Explanation:
This program shows Function Overloading in C++.
The same function name add() is used with:
add(int, int)→ Adds two integersadd(double, double)→ Adds two doublesadd(int, int, int)→ Adds three integers
๐งพ Sample Output:
Sum of two ints: 30 Sum of two doubles: 8 Sum of three ints: 6
๐ Keywords:
C++ function overloading, add function in C++, compile-time polymorphism, OOP concepts, C++ examples
๐ Hashtags:
#CPlusPlus #FunctionOverloading #CppExamples #Polymorphism #OOP #Programming
๐ Search Description:
This C++ program demonstrates function overloading with different parameter lists (integers and doubles). Example of compile-time polymorphism with sample output.
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment