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

int x = 10, y = 5;
void abc (int y)
{
y= y + x;
printf("%d", y);
}
void main ( )
{
int x = 2;
x = x + y;
abc(x);
printf("%d", x);
}
What is the ouput of the following program?



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

The correct option is C 17, 7
Step 1: Global variables 'x' initialized with 10, 'y' initialized with 5.
Step 2: In main function we have local variable 'x' and it has value '2'
Step 3: In main function x = x + y will update value of 'x' of main function and 'x' becomes 7
Step 4: The function call abc(x) will carry '7' and that value copied into 'y' variable of abc ( )
Step 5: y = y+ x in abc ( ) will update 'y' variable value 17 because 'x' in abc( ) is global the print function in abc ( ) prints 17 and print function in main print 7.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Introduction to Outsourcing
BUSINESS STUDIES
Watch in App
Join BYJU'S Learning Program
CrossIcon