ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
int i, c = 0;
for (i = 0; i < 6; i++)
if (i % 2 == 0 || ++c > 1)
c += 10;
printf("%d %d", i, c);- A. 6 60
- B. 6 33
- C. 6 63
- D. 5 63
Correct answer: C. 6 63
|| evaluates its right side only when the left side is false. For even i the left is true, so ++c is skipped and c += 10 runs. For odd i, ++c runs and, since c is already above 1, the condition is true and c += 10 also runs. Even i: 3 × 10; odd i: 3 × 11 → 30 + 33 = 63, and the loop ends with i = 6. 60 forgets the ++c increments.
More C Programming questions
- What is printed? c / 16-bit unsigned short, 32-bit int and unsigned / unsigned short a = 3, b = 5; printf("%d %u %d", a - b, 3u - 5u…
- What is printed? c #define ABS(x) x < 0 ? -x : x printf("%d %d", ABS(2 - 5), ABS(-4) 2);
- What is printed? c const char s = "mississippi"; printf("%td %td %td", strchr(s, 's') - s, strrchr(s, 's') - s, strstr(s, "ssip") - s);
- What is printed? c / 4-byte int / struct V { int a[3]; }; void f(struct V v) { v.a[0] = 9; } void g(int a[3]) { a[0] = 9; } int main(void)…
- What is printed? c int n = 10, c = 0; int k = (n + 3) / 4; switch (n % 4) { case 0: do { c++; case 3: c++; case 2: c++; case 1: c++; }…
- What is printed? c int calls = 0; int ways(int n) { calls++; if (n < 0) return 0; if (n == 0) return 1; return ways(n - 1) + ways(n - 3) +…