ProgrammingVery hardProduct company OA
Assume 8-bit unsigned char. What is printed?
Assume 8-bit unsigned char. What is printed?
printf("%d %d %d", (int)-3.7, (unsigned char)-1, (int)(0.1 * 30));- A. -4 255 3
- B. -3 255 3
- C. -3 255 2
- D. -3 -1 3
Correct answer: B. -3 255 3
Converting a floating value to int truncates toward zero, so −3.7 becomes −3, not −4. −1 converted to unsigned char wraps to 255. 0.1 × 30 is 3.0000000000000004 in binary floating point, which truncates to 3; if it had come out just below 3, it would have printed 2.
More C Programming questions
- What is printed? c int ways(int amt, int k) { static const int c[] = {1, 2, 5}; if (amt == 0) return 1; if (amt < 0 || k == 0) return 0…
- On an LP64 system (8-byte pointers, 4-byte int), what is printed? c int a[10]; printf("%zu %zu %zu", sizeof(&a), sizeof(&a), sizeof(a + 0));
- What is printed? c int i = 0, j = 0; if (i++ & j++) ; if (i++ && j++) ; printf("%d %d", i, j);
- What is printed? c int a[6] = {4, 8, 15, 16, 23, 0}; int find(int x) { a[5] = x; int i = 0; while (a[i] != x) i++; return i < 5 ? i : -1…
- For ints a, b >= 0, which test correctly tells, before adding, whether a + b would overflow?
- What is printed? c const char s = " hi there you "; int words = 0, in = 0; for (; s; s++) { if (s == ' ') in = 0; else if (!in) { in = 1…