ProgrammingModerateAccenture · Cognizant
What is printed?
What is printed?
int a = 0, b = 10;
while (a < b) { a += 3; b -= 2; }
printf("%d %d", a, b);- A. 6 6
- B. 3 8
- C. 9 4
- D. 6 8
Correct answer: A. 6 6
After pass 1: a = 3, b = 8 (3 < 8, continue). After pass 2: a = 6, b = 6, and 6 < 6 is false, so the loop stops. '9 4' runs one extra pass.
More C Programming questions
- After int q = realloc(p, 2 n sizeof q); succeeds (q is not NULL), where p pointed to n ints, which statement is true?
- With int i = 1, x; int a[5] = {0}; which of these statements have undefined behaviour? (i) i = i++ + 1; (ii) a[i] = i++; (iii) i = (i, i +…
- Which of the objects A to E have static storage duration (they live for the whole run of the program, in the data or BSS segment)? c int…
- What is printed? c int cmp(const void a, const void b) { return (const int )b - (const int )a; } int main(void) { int v[] = {4, 9, 1, 7}…
- What is printed? c printf("%d %d %d", atoi("42abc"), atoi(" -7x"), atoi("x9"));
- What is printed? c int a = 0, b = 0; int n = sscanf("12 abc 7", "%d %d", &a, &b); printf("%d %d %d", n, a, b);