Nearby lessons
77 of 124C - Call by Value
Call by Value is one of the foundational topics in C programming. This lesson explains Call by Value with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Call by Value
C passes arguments by value — it gives the function a copy of the value. The function can change its copy, but the original in main() is not affected.
In simple words: call by value is like giving someone a photocopy of your exam answer sheet — they can scribble all over the copy, but your original stays untouched.
Trainer's Note: This surprises every beginner: the function changes x, but main's num stays 10, because num's value (a copy) was passed. To let a function change a variable, we pass its address with pointers — that is Chapter 11's topic (call by reference).
Example01
📝 Key Takeaways
- Functions split code into reusable, readable tasks.
- Three parts: declaration, definition, call.
- Four combinations of arguments and return values.
- C uses call by value — functions get a copy, originals stay unchanged.
- return gives a value back and ends the function.
- Recursion = a function calling itself, with a base case to stop.
- Classic recursion: factorial and Fibonacci.
🧠 Test Your Knowledge
1 QuestionsProgress: 0 / 1