(Bitwise Operators) (I) Left shifting an unsigned int by 1 bit is equivalent to
ID: 3825967 • Letter: #
Question
(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 * (2)^ pow
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
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
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
II.option a
III.option c
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.