ProgrammingHardProduct company OA
What is printed?
What is printed?
int i = 0, c = 0;
while (i < 10 && ++c && i++ % 3 != 2);
printf("%d %d", i, c);- A. 3 2
- B. 2 3
- C. 3 3
- D. 10 10
Correct answer: C. 3 3
Each test increments c and then i (testing the old i). With old i = 0 and 1 the remainder is not 2, so the loop continues; with old i = 2 the test fails, but i has still been incremented to 3. c was incremented on all three tests.
More C Programming questions
- Given this allocation, which code frees everything without leaking or touching freed memory? c int m = malloc(3 sizeof m); for (int i = 0…
- With char a = "hi", b = "hi"; what can be said about the value of a == b?
- What is printed? c int c = 0; for (int i = 1; i <= 4; i++) for (int j = i; j <= 4; j += i) c++; printf("%d", c);
- Assume 16-bit unsigned short and 32-bit int. What is printed? c unsigned short v = 0x1234; unsigned short w = (unsigned short)(v << 8 | v…
- What is printed? c void conv(int n, int b) { if (n >= b) conv(n / b, b); putchar("0123456789ABCDEF"[n % b]); } int main(void) { conv(255…
- A single C source file contains these three lines at file scope. What happens? c int x; int x; int x = 5;