ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int value = 100;
void modify(int value) {
    value = 200;
}
int main(void) {
    modify(value);
    printf("%d", value);
}
  1. A. 200
  2. B. 100
  3. C. Undefined behaviour: value is ambiguous between the parameter and the global
  4. D. Compile-time error: parameter name conflicts with global variable

Correct answer: B. 100

modify's parameter value is a completely separate local variable that merely happens to share the global's NAME; it shadows the global only within modify's own body, and since C passes arguments by value, modifying the parameter never affects the caller's actual argument or the global. main's own global value stays 100.

More C Programming questions

Exams that ask this topic