ProgrammingVery hardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdint.h>
#include <stdio.h>
uint16_t sat(uint16_t a, uint16_t b) {
uint32_t p = (uint32_t)a * b;
return p > 65535u ? 65535 : (uint16_t)p;
}
int main(void) {
printf("%d %d", sat(300, 300), sat(3, 4));
}- A. 65535 12
- B. 65535 90000
- C. 0 12
- D. 12 65535
Correct answer: A. 65535 12
300 * 300 = 90000 is larger than 65535, so the result saturates to 65535, while 3 * 4 = 12 is returned unchanged.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int m[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = i 4…
- How many pairs (i, j) with i < j satisfy a[i] < a[j] for a = {3, 1, 4, 2}? Compute with this program. c #include <stdio.h> int main(void)…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3}, cnt[3], total = 0; for (int i = 0; i < 3; i++) { cnt[i] = 1…
- How many binary strings of length 5 contain no two adjacent 1s? Compute with this recursive program. c #include <stdio.h> int f(int n) {…
- What is printed? c #include <stdio.h> struct item { int w, v; }; int main(void) { struct item items[] = {{1, 10}, {2, 20}, {3, 30}}…
- What is printed? c #include <stdio.h> int main(void) { const char s = "hello"; printf("%c%c", s[1], (s + 4)); }