Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C++ Function Overloading Example (Different Parameters)

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 integers
  • add(double, double) → Adds two doubles
  • add(int, int, int) → Adds three integers
The compiler chooses the correct function based on argument type and count.

🧾 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.

Comments

Popular Posts

πŸŒ™