ProgrammingVery hardCompetitive coding (CP)
What is printed? Assume uint8t is 8 bits.
What is printed? Assume uint8_t is 8 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint8_t x = 0x1F;
uint8_t r = (uint8_t)((x << 4) | (x >> 4));
printf("%d", r);
}- A. 31
- B. 15
- C. 244
- D. 241
Correct answer: D. 241
Swapping the two nibbles of 0x1F gives 0xF1, which is 241. The left shift is truncated to 8 bits by the cast.
More C Programming questions
- What is printed? c #include <stdio.h> #include <stdlib.h> int ds(int n) { int s = 0; while (n) { s += n % 10; n /= 10; } return s; } int…
- How many ordered ways are there to write 6 as a sum of parts 1, 2 and 3? Compute with this program. c #include <stdio.h> int f(int n) { if…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 7; int i = 0; while (x & 1u) { x >>= 1; i++; } printf("%d", i); }
- What is printed? Assume unsigned short is 16 bits. c #include <stdio.h> int main(void) { unsigned short a = 255, b = 255; unsigned c = a…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char w[] = {"ab", "cde"}; char p = w; printf("%d"…
- What is printed? c #include <stdio.h> int main(void) { int a[5] = {0}; int p = a + 4; printf("%ld", (long)(p - &a[0])); }