Saved Bookmarks
| 1. |
Explain the concept of Function Overloading with a C ++ code example. |
|
Answer» Function OVERLOADING is a feature of Object-Oriented PROGRAMMING that allows two or more functions to have the same name but different parameters. When a function name is overloaded with many duties, this is known as function overloading. In Function Overloading, the Function name should be the same, but the ARGUMENTS should be different. Polymorphism is a feature of C++ that allows functions to be overloaded. The following is an example of function overloading in C++: // including the header files#include <bits/stdc++.h>using namespace std;void printValue(int a) { cout << " Integral Value: " << a << endl;}void printValue(char a) { cout << " Character Value" << a << endl;}void printValue(DOUBLE a) { cout << " Decimal Value " << a << endl;}// MAIN function of the C++ codeint main() { // Calls the integral overloaded function printValue(22); // Calls the character overloaded function printValue("C"); // Calls the decimal overloaded function printValue(231.2322); return 0;} |
|