ProgrammingHardProduct company OA
What is printed?
What is printed?
int i = 0, n = 0;
while (i++, i < 4) n += i;
printf("%d %d", n, i);- A. 3 4
- B. 6 4
- C. 6 3
- D. 10 4
Correct answer: B. 6 4
The condition is a comma expression: i is incremented, then i < 4 is the value tested. The body therefore sees i = 1, 2, 3 (n = 6), and the test with i = 4 fails.
More C Programming questions
- What is the range of values of a signed 8-bit two's-complement integer?
- What is printed? c unsigned x = 8; if (x & (x - 1) == 0) puts("pow2"); else puts("not");
- What is printed? c int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, r[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++)…
- What is printed? c const char s = "banana", p = s; int c = 0; while ((p = strchr(p, 'a')) != NULL) { c++; p++; } printf("%d", c);
- Assume IEEE-754 double. What is printed? c printf("%d %d", 0.1 + 0.2 == 0.3, 0.5 + 0.25 == 0.75);
- Assume 4-byte int. What is printed? c printf("%d %d", sizeof(int) -1 < 0, (int)sizeof(int) -1 < 0);