Tip:A–D to answerE for explanationV for videoS to reveal answer
Consider the following function implemented in C:
void test_fun(int x, int y){
int*p;
x=0;
p = &x:
y = *p:
*p =1;
printf(*%d,%d”,x,y)
}
The output of invoking test_fun (10, 10) is
- A.
0, 0
- B.
1, 0
(Correct Answer) - C.
0, 1
- D.
1, 1
Explanation
Solution aur Explanation
Jab hum test_fun(10, 10) ko call karte hain, toh function ke andar variables ki state is tarah badalti hai:
-
Initialization:
Function call ke waqt x=10 aur y=10 assign hote hain.
-
Step 1 (x=0):
Variable x ki value update hokar 0 ho jati hai.
State: x=0,y=10.
-
Step 2 (p=&x):
Pointer p ab variable x ke memory address ko point kar raha hai.
-
Step 3 (y=∗p):
∗p ka matlab hai "value at address p". Kyunki p, x ko point kar raha hai, isliye ∗p ki value 0 hai. Ab y mein 0 assign ho jayega.
State: x=0,y=0.
-
Step 4 (∗p=1):
Yahan hum address p par rakhi value ko 1 kar rahe hain. Kyunki p, x ka address hai, isliye x ki value badal kar 1 ho jayegi.
State: x=1,y=0.
-
Final Step (printf):
printf("%d, %d", x, y) command x aur y ki current values ko print karega.
Output: