ProgrammingModerate
char d[8] = "ab"; strncat(d, "cdefgh", 3); printf("%zu", strlen(d)); What is printed?
- A. 3
- B. 4
- C. 6
- D. 5
Correct answer: D. 5
strncat appends at most 3 characters and then always writes a terminator, so d becomes 'abcde'. Its length is 5 and the write stays inside the 8 bytes.
More C Programming questions
- Which statement about the value returned by strcmp("apple", "Apple") is guaranteed by the C standard?
- char s[] = "abcdef"; memmove(s + 2, s, 4); printf("%s", s); What is printed?
- char a[10] = "hi"; printf("%zu", sizeof(a) - strlen(a) - 1); What is printed?
- char s[] = "xyz"; char p = s; p[0] = 'a'; printf("%s %zu", s, sizeof s); What is printed?
- char b[4]; int r = snprintf(b, 4, "%d", 123456); printf("%d %s", r, b); What is printed?
- int pal(const char s) { int i = 0, j = (int)strlen(s) - 1; while (i < j) if (s[i++] != s[j--]) return 0; return 1; } How many of "a"…