ProgrammingHardTCS NQT · Infosys pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int x = 0xFF;
int y = x & 0x0F;
int z = (x >> 4) & 0x0F;
printf("%d %d", y, z);- A. 15 15
- B. 0 15
- C. 15 0
- D. 255 0
Correct answer: A. 15 15
0xFF & 0x0F isolates the low 4 bits (the nibble), giving 0xF=15. Shifting right by 4 first moves the high nibble into the low position; ANDing with 0x0F then isolates that nibble too, which for 0xFF is also 0xF=15 (since both nibbles of 0xFF are F).
More C Programming questions
- Assume 32-bit int. What is printed? c unsigned int a = 5; int b = -3; printf("%d", a + b > 0);
- Assume 32-bit int. What is printed? c int x = 3; int y = 1 << x | 1; printf("%d", y);
- Assume 32-bit int. What is printed? c int permissions = 0; #define READ 4 #define WRITE 2 #define EXEC 1 permissions |= READ | WRITE…
- What happens when this runs? c int main(void) { int arr[3]; for (int i = 0; i < 3; i++) { printf("%d ", arr[i]); } }
- What happens when this runs? c void f(int p) { free(p); p = 10; } int main(void) { int x = malloc(sizeof(int)); f(x); printf("done"); }
- What happens when this runs? c int compute(int a, int b) { int result; if (a > b) { result = a - b; } return result; } int main(void) {…