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?

  1. A.

    The function receives a copy of the variable's value

  2. B.

    The function alters the original variable directly

  3. C.

    The function accesses the memory location of the variable

  4. 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.

Explore the full course: Rssb Senior Computer Instructor