Nearby lessons
49 of 72C - Types of Functions
C functions come in four forms, based on whether they take arguments and whether they return a value. This lesson shows all four forms using the same sum task so the differences are easy to see.
Form 1 — No Arguments, No Return
The function takes nothing in and sends nothing back. It performs a fixed action — here it prints the sum of two values written inside it:
Example01
Form 2 — Arguments, No Return
The function takes input through its parameters but returns nothing. It displays the sum of whatever it is given:
Example02
Form 3 — No Arguments, Returns a Value
The function takes nothing but hands a value back to the caller. Here it reads two numbers itself and returns their sum:
Example03
Form 4 — Arguments and a Return Value
The most useful form: inputs in, result out, no printing inside. Easy to test and easy to reuse anywhere a value is needed:
Example04
📝 Key Takeaways
- The four forms: no args/no return, args/no return, no args/return, args/return.
- The args-and-returns form is the most useful and most testable.
- A void function performs an action; a non-void function produces a value.
- Separate computing from printing whenever the result may be reused.
🧠 Test Your Knowledge
4 QuestionsProgress: 0 / 4