What happens when a variable is passed by value to a function in C?
2025
What happens when a variable is passed by value to a function in C?
- A.
The function receives a copy of the variable's value
- B.
The function alters the original variable directly
- C.
The function accesses the memory location of the variable
- D.
The function gets a reference to the original variable
Attempted by 182 students.
Show answer & explanation
Correct answer: A
When a variable is passed by value in C, the system allocates a new memory slot on the call stack for the function's parameter and copies the original variable's data into it. Because the function operates within its own isolated stack frame using this duplicate, any modifications made to the parameter are strictly local. The function remains completely blind to the original variable's memory address, ensuring that the caller's original data remains entirely unaffected and unchanged.