ProgrammingVery hardProduct company OA
What is printed?
What is printed?
char src[] = "abc", dst[8];
char *d = dst;
const char *s = src;
while ((*d++ = *s++));
printf("%s %td %td", dst, d - dst, s - src);- A. abc 3 3
- B. abc 4 3
- C. abc 3 4
- D. abc 4 4
Correct answer: D. abc 4 4
Each test copies a character and then checks it, so the '\0' is copied too and ends the loop. Both pointers are incremented on that last copy as well, so each has moved 4 places. '3 3' forgets that the terminator was copied.
More C Programming questions
- What does calloc(n, size) guarantee that malloc(n size) does not?
- What is printed? c int a[3][3] = {{1}, {2, 3}, [2][1] = 7}; printf("%d %d %d %d", a[0][1], a[1][1], a[2][0], a[2][1]);
- What does f(6) print? c void f(int n) { printf("%d", n); if (n > 1) f(n / 2); printf("%d", n); }
- What is printed? c sizet a = 3, b = 5; if (a - b > 0) puts("bigger"); else puts("smaller");
- What is printed? c int g(int a, int b) { return a == b ? a : a > b ? g(a - b, b) : g(a, b - a); } int main(void) { printf("%d", g(48…
- How many bytes does this code leak? c for (int i = 0; i < 3; i++) { char p = malloc(10); if (i == 1) free(p); }