Unformatted text preview:

C FUNCTIONS What is function overloading C Function Overloading In C function overloading means that you can create multiple functions with the same name but different parameters This allows you to reuse function names while providing flexibility in the types of data that can be passed as parameters Creating Overloaded Functions To create overloaded functions you need to declare the functions with the same name but different parameters For example int sum int a int b double sum double a double b float sum float a float b float c Note that these functions have the same name but different parameter types and numbers Defining Overloaded Functions After declaring the overloaded functions you need to define them For example int sum int a int b return a b double sum double a double b return a b float sum float a float b float c return a b c Here we define the functions with the same name as the declarations but with the appropriate parameter types and return types Note that the function bodies are different for each overloaded function Testing Overloaded Functions To test the overloaded functions you can invoke them in your main function For example int main std cout sum 4 3 std endl Output 7 std cout sum 4 4 3 3 std endl Output 7 7 std cout sum 4 4 3 3 2 2 std endl Output 10 9 return 0 Here we invoke the overloaded functions with different parameter types and numbers The appropriate function is called depending on the data types passed as parameters


View Full Document

IAIA CS 124 - C++ Function Overloading

Documents in this Course
Load more
Download C++ Function Overloading
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view C++ Function Overloading and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view C++ Function Overloading and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?