ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int x = 100;
void f(int *p) {
    int y = 200;
    p = &y;
}
int main() {
    int *p = &x;
    f(p);
    printf("%d", *p);
}
  1. A. 200
  2. B. 100
  3. C. Compilation error
  4. D. Undefined behavior: y no longer exists

Correct answer: B. 100

p is passed BY VALUE (a copy of the pointer), so reassigning the local parameter p inside f to &y only changes that function's own copy — main's p still points at x, unaffected. Printing *p gives 100.

More C Programming questions

Exams that ask this topic