When to use pass by
value, pass by reference, void data types with functions
|
Purpose |
Function Type |
Parameters |
To Return Result |
|
To compute or obtain as input a single numeric or character value |
Same as type of value to be computed or input. |
Input parameters hold copies of data provided by calling function. |
Function code includes a return statement with an expression whose value is the result. |
|
To produce printed output containing values of numeric or character arguments. |
void |
Input parameters hold copies of data provided by calling function. |
No result is returned. |
|
To compute multiple numeric or character results |
void |
Input parameters hold copies of data provided by calling function. Output parameters are pointers to actual arguments |
Results are stored in the calling function’s data area by indirect assignment through output parameters(pointers). There is no return statement. |
|
To modify argument values |
void |
Input/output parameters are pointers to actual arguments. Input data is accessed by indirect reference through parameters. |
Results are stored in the calling function’s data area by indirect assignment through output parameters. There is no return statement. |