8 a]Discuss the various ways of passing parameter to the functions.
- Void Functions without parameters – No arguments and no return values
➢ When a function has no arguments, it does not receive any data from the calling function.
➢ Similarly, when it does not return a value, the calling function does not receive any data from the called function.
No data communication between functions
2. Void Functions with parameters – Arguments but no return values
➢ The calling function accepts the input, checks its validity and pass it on to the called function.
➢ The called function does not return any values back to calling function.
The actual and formal arguments should match in number, type and order as shown in above Figure
One way data communication
Arguments matching between the function call and the called funtion
In this example a photocopy of value stored in ‘num’ (i.e. 5) is made in ‘no’ and finally displayed on screen
3. Functions with parameters and return values – Arguments with return values
➢ The calling function sends the data to called function and also accepts the return values from called function.
➢ Actual Parameters: When a function is called, the values that are passed in the call are called actual parameters.
➢ Formal Parameters: The values which are received by the function, and are assigned to formal parameters.
two way data communication between functions
4 .Functions without parameters and with return values – No arguments but returns values
➢ The calling function does not send any data to called function and but, accepts the return values from called function.
➢ Global Variables: These are declared outside any function, and they can be accessed on any function in the program.
➢ Local Variables: These are declared inside a function, and can be used only inside that function.