CHAPTER 17 / 26
C Return Values
Learn how functions return results to the calling code.
01 — Syntax
return value;
02 — Example
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
printf("Result = %d", add(10, 20));
return 0;
}03 — Important Points
- A return statement sends a value back to the caller.
- Use void when a function returns no value.
04 — Common Mistakes
- Returning the wrong type.
- Forgetting to return a value from a non-void function.
05 — Real-World Use
Return values let functions communicate results to other parts of a program.
06 — Practice
Create a small program that demonstrates the main idea of C Return Values.