Question

4. (10 pts) Show the output of the following program: (list the program outputs in the order as they would appear on screen)

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

Solution:

Trace the code by each line to check the output printed by the program

In the first statement of Main() function we are declaring a variable x and y variables and initate variable x with value 2.

In next line call the function Mystery() by passing the value x-1 i.e Mystery(1) and then add the value 1 to returned the result and store in variable y.

In Mystery() function

we are declaring a variable y and initializing value as 5 and in next line declaring a variable result of type int.

in next line y=y+num i.e y=5+1=6

In next line we are printing the values y and num the output is

y=6, num=1

in next line modify result variable result=y+num i.e result=7 and then return the result.

The execution will go to main function and will print the x and y values so the output is

x=2, y=8

In next line call the Mystery() function by passing 2*x value is 2*2=4 i.e Mystery(4)

Now the execution will go to Function Mystery()

In Mystery() function

y value will be y+num i.e =5+4=9

so the output printed in the function is

y=9, num=4

In next line we are modifying the result result=num+y=13 will be returned

so the output printed in main function is

x=2, y=13

So the final output is

y=6, num=1

x=2, y=8

y=9, num=4

x=2, y=13

Note: if you have any queries please post a comment thanks a lot..always available to help you...

Add a comment
Know the answer?
Add Answer to:
4. (10 pts) Show the output of the following program: (list the program outputs in the...
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