Nearby lessons

77 of 124

C - 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
CCode Cell
1#include <stdio.h>
2 
3void change(int x)
4{
5 x = 100; // changes only the copy
6}
7 
8void main()
9{
10 int num = 10;
11 change(num);
12 printf("%d\n", num); // still 10 - original unchanged
13}
Output
10
📝 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 Questions
Progress: 0 / 1