ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a = 0, b = 0, c = 0;
if ((a = 2) && (b = 0) || (c = 3)) a++;
printf("%d %d %d", a, b, c);- A. 2 0 0
- B. 2 0 3
- C. 3 0 3
- D. 3 0 0
Correct answer: C. 3 0 3
These are assignments, not comparisons. (a = 2) is true, (b = 0) is false, so the && is false and || must evaluate (c = 3), which is true. The if body then makes a 3. '3 0 0' short-circuits the || wrongly.
More C Programming questions
- Which line has undefined behaviour? c char a[] = "hi"; char p = "hi"; a[0] = 'H'; / (i) / p[0] = 'H'; / (ii) / char q = a; q[1] = 'I'; /…
- What is printed? c int calls = 0; int C(int n, int k) { calls++; return (k == 0 || k == n) ? 1 : C(n - 1, k - 1) + C(n - 1, k); } int…
- What is printed? c enum E { A = -2, B, C, D = A + 10, E2 }; printf("%d %d %d", B, C, E2);
- What is printed? c int steps(int n) { return n == 1 ? 0 : 1 + steps(n % 2 ? 3 n + 1 : n / 2); } int main(void) { printf("%d %d", steps(6)…
- Assume ASCII. What does f("Code21") print? c void f(const char s) { if (s) { f(s + 1); if (s % 2) putchar(s); } }
- What is printed? c int a = 1, b = 2, c = 3; int arr[] = {&a, &b, &c}; int pp = arr + 1; pp += 10; pp[1] += 20; printf("%d %d %d", a, b, c);