Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10.1. What will be the output of the following code segment? int u = 21; int v =

ID: 3821797 • Letter: 1

Question

10.1. What will be the output of the following code segment?

int u = 21;

int v = 10;

if (u && v) printf(“ Time to move on!! ”);

if (u & v) printf(“Do it today!! ”);

a. Time to move on!!

b. Do it today!!

c. Time to move on!! Do it today!!

d. None of the above

10.2. Given the following declaration char x = -12; char y = 63; if the computer uses 2’s complement to represent the numbers then which statement is correct:

a. The number of bits in x is equal to the number of bits in y

b. The number of bits in x is less than the number of bits in y

c. The number of bits in x is greater than the number of bits in y

Explanation / Answer

1.

In the first Question, the variables u stores 21 and v stores 10. In the first "if" condition the statements are executed if the result of the u&&v (LOGICAL AND) is non zero. Here 21 and 10 both are non zero hence it turns out to be Non Zero and the statement in the 'If' condition gets executed.

But, when it comes to second if condition it has u&v (BITWISE AND). That means there is computation of the BITWISE AND between 21 (10101 in binary) and 10 (01010 in binary) which turns of to be Zero.Hence, the control does not goes inside this.

Hence the Output is only "Time to move on !!".

2.

The numbers will be stored in 2's complement in the memory.

The negative number i.e -1 will be saved as 11110100 where as the positive number i.e 63 will be saved as 111111 . Its clearly visible that x needs more bits than y.

I hope my answer has helped you. Feel free to contact me in case of any doubts.Good Luck !

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote