ProgrammingVery hard
char s[] = "abcdef"; memmove(s + 2, s, 4); printf("%s", s); What is printed?
- A. ababab
- B. ababcd
- C. abcdef
- D. ababcdef
Correct answer: B. ababcd
memmove behaves as if the source were copied to a temporary first, so 'abcd' lands intact at positions 2 to 5. A forward byte-by-byte copy, memcpy style, would overwrite its own source and give 'ababab'.
More C Programming questions
- 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"…
- char s[] = "xyz"; for (int i = 0; s[i]; i++) s[i] = (s[i] - 'a' + 3) % 26 + 'a'; printf("%s", s); What is printed?
- char d[8] = "#######"; strncpy(d, "ab", 5); int z = 0; for (int i = 0; i < 8; i++) if (d[i] == 0) z++; printf("%d", z); What is printed?