ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
int i = 0, s = 0;
top:
s += i;
if (++i < 5) goto top;
printf("%d %d", s, i);- A. 15 5
- B. 6 4
- C. 10 4
- D. 10 5
Correct answer: D. 10 5
The goto builds a loop that adds i = 0, 1, 2, 3, 4 (total 10). ++i reaches 5 on the last test, which fails, so i ends at 5. '15' wrongly adds 5 as well.
More C Programming questions
- What is printed? c int calls = 0; int mx(int a, int lo, int hi) { calls++; if (lo == hi) return a[lo]; int m = (lo + hi) / 2; int l =…
- What is printed? c int a[] = {1, 2, 3}, p = a; int x = ++p++; int y = p++ 10; printf("%d %d %d %d", x, y, a[0], p);
- What is printed? c int x = 10; int p = &x, pp = &p; printf("%d", pp + p 2);
- What is printed? c const char s = " 42, 17"; printf("%zu %zu", strspn(s, " "), strcspn(s, ","));
- A header config.h is wrapped as #ifndef CONFIGH / #define CONFIGH / … / #endif. What problem does this prevent?
- With 4-byte int, after these lines run, which block can no longer be freed because no pointer to it remains? c int a = malloc(10…