Question

What will be the value of x printed by the following code (modify_x() function)? #include <stdio.h> void modify_x(void) int x

In earlier question (modify_x() function based), what would you do to have different values in the output upon execution of t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer to First Question::

From main method modify_x() function is called 2 times.

If we check the function_x() function, we can see that it is not taking any function argument.

The function has a local variable x which is initialized to 10.

At the next statement (x+=20), it is basically doing x = x +20. i.e, the previous value of local variable x

is increased by 20.

So new value pof x become = 10+20 = 30

So, at the end of execution of first program, modify_x() will print 30.

Since the program will do the same thing again, it will again print 30.

Answer to Second Question:

In order to print differet values in the output, we can pass value of x as functon argument for modify_x().

So our new function definition will be:

void modify_x(int x){

x = x+20;

print("x is %d", x);

}

so if we are calling modify_x(20), which is followed by modify_x(30) ; then output will be like:

for first case , x is (20+20)=40

In second case:modify_x(30) will have output like 30+20 = 50

Add a comment
Know the answer?
Add Answer to:
What will be the value of x printed by the following code (modify_x() function)? #include <stdio.h>...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT