ProgrammingHardWipro NLTH · C
What is printed?
What is printed?
int i, j;
for (i = 0, j = 5; i < j; i++, j--)
;
printf("%d %d", i, j);- A. 2 3
- B. 3 3
- C. 3 2
- D. 4 1
Correct answer: C. 3 2
The pairs go (0,5), (1,4), (2,3), (3,2); at (2,3) i < j still holds so both change once more, and then 3 < 2 fails.
More C Programming questions
- What is printed? c int a = 0, b = 0, c; c = (a++ && b++) || (++a || b++); printf("%d %d %d", a, b, c);
- What is printed? c int a = -1; unsigned int b = 1; printf("%d %d", a < b, a < (int)b);
- What is printed? c int f(int n) { return n <= 1 ? 1 : f(n - 1) + f(n - 2) + n; } int main(void) { printf("%d", f(5)); return 0; }
- What is printed? c void g(int a[]) { printf("%d ", (int)(sizeof(a) == sizeof(int ))); } int main(void) { int a[10]; g(a); printf("%zu"…
- What is printed? c char s[20] = "abc"; strcat(s, "de"); strncpy(s + 1, "XYZW", 2); printf("%s %zu", s, strlen(s));
- What is printed? c int n = printf("ab%d", 123); printf(" %d", n);