What is the output of the following program ? #include<stdio.h> void f(int *p,…
2026
What is the output of the following program ?
#include<stdio.h>
void f(int *p, int *q) {
p = q;
*p = 2;
}
int i = 0, j = 1;
int main(void){
f(&i, &j);
printf("%d %d\n", i, j);
}- A.
2 2
- B.
2 1
- C.
0 1
- D.
0 2
Attempted by 100 students.
Show answer & explanation
Correct answer: D
The program passes pointers to i and j. Inside f, p=q makes p point to j's address, then *p=2 changes j to 2. Since i is never modified through pointer dereference, it remains 0. Output should be '0 2'.