CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

int x=2;
int f(int x, int *p)
{
*p = x+3;
x = *p;
return x;
}
void main ( )
{
x = 5;
x=f(x, & x);
printf("%d",x)
}
Output of the above program is

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

The correct option is B 8
Step 1: Global variable initialized with value '2' assume its address starts with 100



Step 2: main( ) updates global variable 'x' with '5' and f(x, & x) will pass values of x, address of x as arguments to called function. So local variables of f() are x, p containing values of global variable 'x' and address of global variable 'x' respectively. So *p=x+3 will update global variable 'x' with 8. And that value assigned to local variable 'x' of f().

return 'x' of f() will return '8' and this '8' will be initialized to Global variables 'x' so printf statement will print '8' output.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
A+B+C=N (N Fixed)
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon