Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

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

πŸŒ™