ProgrammingHardProduct company OA
Assume 8-bit unsigned char. What is printed?
Assume 8-bit unsigned char. What is printed?
int i; unsigned char c; double d;
d = c = i = 300 + 0.7;
printf("%d %d %.1f", i, c, d);- A. 300 44 300.7
- B. 300 44 300.0
- C. 300 44 44.0
- D. 301 45 45.0
Correct answer: C. 300 44 44.0
Assignment groups right to left and each step converts to the target's type. i gets 300.7 truncated to 300; c gets 300 mod 256 = 44; d gets c's value, 44.0. The chain does not pass 300.7 to every variable.
More C Programming questions
- Why is memcmp(&a, &b, sizeof a) == 0 an unreliable way to test whether two struct variables a and b have equal members?
- What is printed? c int c = 0; int f(int n) { c++; return n > 0 && (f(n - 1) || f(n - 2)); } int main(void) { int r = f(4); printf("%d %d"…
- What is printed? c char buf[32], p = buf; for (int i = 1; i <= 4; i++) p += sprintf(p, "%d,", i i); p[-1] = '0'; printf("%s %td", buf, p…
- How many swaps does this selection sort perform? c int a[] = {3, 1, 2, 5, 4}, sw = 0; for (int i = 0; i < 4; i++) { int m = i; for (int j…
- How many element shifts (executions of a[j + 1] = a[j]) does this insertion sort make? c int a[] = {4, 3, 2, 1}, shifts = 0; for (int i =…
- How many passes of the outer loop run? c int a[] = {2, 3, 4, 5, 1}, passes = 0; for (int sw = 1; sw; ) { sw = 0; passes++; for (int j = 0…