ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
int i = 5;
printf("%d ", i++);
printf("%d", ++i);- A. 6 7
- B. 5 7
- C. 5 6
- D. 6 8
Correct answer: B. 5 7
i++ yields the old value (5) and then makes i 6. ++i increments first (to 7) and yields the new value. The two calls are separate statements, so the order is well defined.
More C Programming questions
- What is printed? c printf("%.2f %d %d", 7 / 2.0, 7 / 2, 7 % 2);
- What is printed? c int x = 5; void f(void) { int x = 1; x++; } void g(void) { x++; } int main(void) { f(); g(); g(); printf("%d", x); }
- What is printed? c char s = "programming"; int c = 0; while (s) if (s++ == 'm') c++; printf("%d %c", c, (s - 1));
- What is printed? c unsigned x = 0xF0; / 32-bit unsigned / printf("%u %u %u %u", x >> 4, x << 1, x & 0x3C, x | 0x0F);
- What is printed? c int s = 0, i; for (i = 0; i < 10; i++) { if (i % 3) continue; s += i; } printf("%d %d", s, i);
- What is printed? c struct P { int x, y; } p = {3, 4}, q = &p; q->x += q->y; (q).y = 2; printf("%d %d", p.x, p.y);