Multiply Function that works for All Numeric Types in C++ Last Updated : 16 Jun, 2025 Comments Improve Suggest changes Like Article Like Report In C++, function overloading allows us to create multiple functions with the same name but different parameter types. Using this concept, we can multiply functions to perform multiplication on numeric values of different data types.This program should be able to do the following:Multiply two int values.Multiply two double values.Multiply an int and a double (or vice versa).Multiply two numeric strings after converting them to numbers.Implementation C++ #include <bits/stdc++.h> using namespace std; // Multiply two integers int multiply(int a, int b) { return a * b; } // Multiply two doubles double multiply(double a, double b) { return a * b; } // Multiply int and double double multiply(int a, double b) { return a * b; } // Multiply double and int double multiply(double a, int b) { return a * b; } // Multiply two numeric strings double multiply(const string& a, const string& b) { double num1, num2; stringstream ss1(a), ss2(b); ss1 >> num1; ss2 >> num2; return num1 * num2; } int main() { cout << "Int * Int: " << multiply(3, 4) << endl; cout << "Double * Double: " << multiply(2.5, 4.0) << endl; cout << "Int * Double: " << multiply(3, 4.5) << endl; cout << "Double * Int: " << multiply(5.5, 2) << endl; cout << "String * String: " << multiply("6.5", "2"); return 0; } OutputInt * Int: 12 Double * Double: 10 Int * Double: 13.5 Double * Int: 11 String * String: 13The compiler chooses the appropriate multiply function based on the argument types. For string inputs, we convert the numeric string values into double using stringstream and then perform multiplication. Comment More infoAdvertise with us Next Article Multiply Function that works for All Numeric Types in C++ A abhishekcpp Follow Improve Article Tags : C++ C++ Basic Programs Practice Tags : CPP Similar Reads multiset empty() function in C++ STL The multiset::empty() function is a built-in function in C++ STL which checks if the multiset is empty or not. It returns true if the multiset is empty, else it returns false. Syntax: multiset_name.empty() Parameters: The function does not accept any parameter. Return Value: The function returns tru 1 min read unordered_multiset bucket() function in C++ STL The unordered_multiset::bucket() is a built-in function in C++ STL which returns the bucket number in which a given element is. Bucket size varies from 0 to bucket_count-1. Syntax: unordered_multiset_name.bucket(element) Parameters: The function accepts a single mandatory element which specifies the 2 min read Inbuilt function for calculating LCM in C++ Many times while we do programming, we need to calculate the Least Common Multiple (LCM) between two numbers. We have already discussed how to find LCM in this post. In place of defining and then using a function for calculating lcm , we can simply use an inbuilt function of boost library of C++ , b 2 min read iswctype() function in C/C++ The iswctype() is a built-in function in C/C++ which checks if a given wide character has a certain property. It is defined within the cwctype header file of C/C++ Syntax: int iswctype(wint_t wc, wctype_t desc) Parameter: The function accepts two mandatory parameter which are described below: wc - T 2 min read wctype() function in C/C++ The wctype() is a built-in function in C/C++ which returns a value of type wctype_t that is used for classifying a wide character. It is defined within the cwctype header file of C++. The following are the possible type wctype_t: Value of str Equivalent function space iswspace upper iswupper xdigit 2 min read Like