Pages

Monday, March 31, 2025

Function Overloading in Functions in C++

 int sum(int a , int b) {

    cout << (a+b) << endl;
    return a + b;
}

double sum(double a, double b) {
    cout << (a+b) << endl;
    return a + b;
}


int sum(int a, int b, int c){
    cout << (a+b+c) << endl;
    return a + b+ c;
}
int main(){

    sum(2,3);
    sum(12, 13);
    sum(1.5, 2.5); //  4
    sum(1,2,3);

    return 0;
}

OUTPUT-
5 25 4 6

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...