...
Programming-for-Output-Problems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023

Programming-for-Output-Problems

Question 2

Consider the following C function.

               void convert (int n) {
                       if (n < 0)
                          printf ("%d", n);
                       else {
                          convert (n/2);
                          printf ("%d", n%2);
                       }
               }

Which one of the following will happen when the function convert is called with any positive integer n as argument?

A
It will print the binary representation of n in the reverse order and terminate.
B
It will not print anything and will not terminate.
C
It will print the binary representation of n and terminate.
D
It will print the binary representation of n but will not terminate.
Question 2 Explanation: 
////////////////OUTPUT
Sequence of function calls

Convert(6)
Convert(3)
Convert(1)

Convert(0)
:
Convert(0)
:
:
It will not terminate and never produce any output.
Note:
There is no instruction which stops the loop.

Correct Answer: B
Question 2 Explanation: 
////////////////OUTPUT
Sequence of function calls

Convert(6)
Convert(3)
Convert(1)

Convert(0)
:
Convert(0)
:
:
It will not terminate and never produce any output.
Note:
There is no instruction which stops the loop.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!