5.6Categories of Functions: Arguments and Return Values
Covers IGNOU MCS-201 §5.7
Functions differ in how they exchange data with the caller: some need inputs, some give back a result, some do both and some neither. This section covers the four combinations and the terms for the values passed in a call.
Actual and formal arguments
| Term | Also called | Where it appears | Example |
|---|---|---|---|
| Actual arguments | Arguments | In the function call | sum(a1, a2, a3) |
| Formal arguments | Parameters | In the function header | void sum(int f1, int f2, int f3) |
When the call happens, the value of each actual argument is copied into the matching formal argument. They must agree in number, order and type (or be convertible to the parameter’s type).
The four categories
| Category | Arguments | Return value | Data flow | Example prototype |
|---|---|---|---|---|
| 1 | No | No | None; only control is transferred | void message(void); |
| 2 | No | Yes | Function → caller | int cal_sum(void); |
| 3 | Yes | No | Caller → function | void show_sum(int, int, int); |
| 4 | Yes | Yes | Both ways | int sum(int, int, int); |
Which category to choose
- Prefer category 4 for calculations: inputs come as arguments, and the result goes back with
return. The caller decides what to do with the result. - Use category 3 for actions on given data, such as printing a report.
- Use category 1 or 2 when the function needs no information from the caller, such as printing a menu or reading a value from the user.
Key takeaways
- Actual arguments are in the call; formal arguments (parameters) are in the definition.
- They must match in number, order and type.
- Four categories: no arguments/no return, no arguments/return, arguments/no return, arguments/return.
- Functions with arguments and a return value are the most flexible.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Write a category 4 function simple_interest that takes principal, rate and time and returns the interest, and compute it for 10000, 5 and 2.
Show worked answer
float simple_interest(float p, float r, float t) { return p * r * t / 100; }. Call: si = simple_interest(10000, 5, 2);. The actual arguments 10000, 5 and 2 are copied to the formal arguments p, r and t. The function computes 10000 × 5 × 2 ÷ 100 = 1000 and returns 1000.0, which is stored in si.