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

2- (Bitwise Operators) (I) Left shifting an unsigned int by 1 bit is equivalent

ID: 3778594 • Letter: 2

Question

2- (Bitwise Operators)

(I) Left shifting an unsigned int by 1 bit is equivalent to multiplying the

value by 2. Write a function power2 that takes two integer arguments number and pow and calculates

number * 2pow

Use the shift operator to calculate the result. Print the values as integers and as bits.

(II) What is the output of this C code?

#include <stdio.h>

1. void main()

2. {

3. int a = 5, b = -7, c = 0, d;

4. d = ++a && ++b || ++c;

5. printf(" %d%d%d%d", a, b, c, d);

6. }

a) 6 -6 0 0

b) 6 -5 0 1

c) -6 -6 0 1

d) 6 -6 0 1

(III) What is the output of this C code?

1. #include <stdio.h>

2. int main()

3. {

4. int x = 2;

5. int y = -4

6. x = x << 1;

7. y = y >> 1;

8. printf("%d %d ", x, y);

9. }

a) 4 -2

b) 1 -8

c) Depends on the compiler

d) Compiler error

Explanation / Answer

1)

//functon definition

power2(long number,long pow)

{

}

2)option D

6 -6 0 1

work with incrementation,operator precedence and associativity

3) compiler error OPTION D

reason:semicolon is missing in y=-4 i.e line number 5

If SEMCOLON is corrected in line 5,then answer is option A i.e 4,-2

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