wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

What does the following program print?
#include < stdio.h>
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main( )
{
f(&i, &j);
printf ("%d %d\n", i, j);
return 0;
}

A
2 2
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
0 1
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
0 2
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
2 1
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C 0 2
In the given program it begin from main function,
i and j are globally initialized by 0 and 1. So when we call function f(& i, & j) the address of i and j are passed.
when p = 1 and *p = 2 means
*q = 2. so value of *q is passed.
and value of *q return to j.
Value of i and j are 0 and 2 respected.
So printf("%d %d," i, j) gives output (0, 2)

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Integration as Anti-Derivative
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon