The literal meaning of function is an activity intended for a person or a thing. In programming, function is work or operation that is performed to get the desired output.
There are 3 steps of creating and executing a function :
- Declaring a function
- Defining a function
- Calling a function
For Example: Let’s create a sum function that carries out the sum of two numbers.
Step 1: Declaring a function: Giving a name to the function and memory is allocated for the function
Step 2: Defining a Function: Writing the code inside the function that will produce the desired output.
Step 3: Final step is to invoke/call the function so that the statements written inside the function are executed. You have to call the function to get the desired output. If you have defined the function and not called it, no output will be produced.