ProgrammingHardProduct company OA
Assume 8-bit unsigned char. What is printed?
Assume 8-bit unsigned char. What is printed?
int n = 0;
for (unsigned char c = 0; c < 300; c++) {
n++;
if (n > 1000) break;
}
printf("%d", n);- A. 255
- B. 256
- C. 300
- D. 1001
Correct answer: D. 1001
An unsigned char never exceeds 255; after 255, c++ wraps it to 0. c < 300 is therefore always true and only the break ends the loop, when n reaches 1001. '256' assumes the loop stops at the wrap.
More C Programming questions
- Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed? c int big = 16777217; / 2^24 + 1 / float f = big; printf("%d"…
- Assume 8-bit unsigned char. What is printed? c int i; unsigned char c; double d; d = c = i = 300 + 0.7; printf("%d %d %.1f", i, c, d);
- 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…