ProgrammingHard
char s[10] = "xyz"; strcpy(s + 1, "ab"); printf("%s", s); What is printed?
- A. xyab
- B. abz
- C. xabz
- D. xab
Correct answer: D. xab
strcpy writes ab and its terminator starting at index 1, so the first character x stays and the string ends after b.
More C Programming questions
- char s[] = "hello"; char p = s; while (p) { if (p == 'l') p = 'L'; p++; } printf("%s", s); What is printed?
- char s = "abc"; char t[4]; strcpy(t, s); t[1] = 'X'; printf("%s", t); What is printed?
- char buf[5] = "abcd"; buf[4] = 'e'; printf("%.5s", buf); What is printed (no terminator is present, which is defined)?
- char s[] = "AbC"; for (char p = s; p; p++) p = isupper((unsigned char)p) ? tolower((unsigned char)p) : toupper((unsigned char)p)…
- int count = 0; for (const char p = "a1b22c"; p; p++) if (isdigit((unsigned char)p)) count++; printf("%d", count); What is printed?
- char name[8] = "Sam"; printf("%d %d", (int)sizeof name, (int)strlen(name)); What is printed?