ProgrammingHardTCS NQT · Infosys pattern
What is printed? (Assume int is 32 bits, two's complement.)
What is printed? (Assume int is 32 bits, two's complement.)
unsigned int a = 0xF0F0F0F0;
unsigned int b = a >> 4;
printf("%X", b);- A. F0F0F0F
- B. FF0F0F0F
- C. 0F0F0F0F
- D. F0F0F0F0
Correct answer: C. 0F0F0F0F
a is unsigned, so >> is a LOGICAL shift: zeros fill from the left. 0xF0F0F0F0 >> 4 shifts every hex digit right by one position, bringing in a 0 at the top: 0x0F0F0F0F.
More C Programming questions
- What is printed? (Assume int is 32 bits, two's complement, arithmetic right shift for signed negatives — the common but…
- What is printed? (Check if a number is a power of two.) c int isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; } int main(void) {…
- What is printed? c int swaptrick(int a, int b) { a = a ^ b; b = a ^ b; a = a ^ b; printf("%d %d ", a, b); return a + b; } int main(void) {…
- What is printed? c #define SETBIT(x, n) ((x) | (1 << (n))) #define CLEARBIT(x, n) ((x) & ~(1 << (n))) #define TOGGLEBIT(x, n) ((x) ^ (1 <<…
- What is printed? c #define SQUARE(x) x x int main(void) { int a = 5; printf("%d", SQUARE(a + 1)); }
- What is printed? c #define TWICE(x) x + x printf("%d", 2 TWICE(3));