ProgrammingHardProduct company OA
What is printed?
What is printed?
int i = 0, j = 0;
if (i++ & j++) ;
if (i++ && j++) ;
printf("%d %d", i, j);- A. 1 1
- B. 2 2
- C. 2 1
- D. 2 0
Correct answer: B. 2 2
Bitwise & always evaluates both operands, so the first line makes i = 1 and j = 1. In the second, i++ yields 1, which is true, so && goes on to evaluate j++: i = 2, j = 2. '2 1' treats & as if it short-circuited.
More C Programming questions
- What is printed? c int a[6] = {4, 8, 15, 16, 23, 0}; int find(int x) { a[5] = x; int i = 0; while (a[i] != x) i++; return i < 5 ? i : -1…
- For ints a, b >= 0, which test correctly tells, before adding, whether a + b would overflow?
- What is printed? c const char s = " hi there you "; int words = 0, in = 0; for (; s; s++) { if (s == ' ') in = 0; else if (!in) { in = 1…
- What is printed? c int sub(const char a, const char b) { / is a a subsequence of b? / if (!a) return 1; if (!b) return 0; return sub(a ==…
- What is printed? c char src[] = "abc", dst[8]; char d = dst; const char s = src; while ((d++ = s++)); printf("%s %td %td", dst, d - dst, s…
- What does calloc(n, size) guarantee that malloc(n size) does not?