ProgrammingModerate
char s[] = "hello world"; char *w = strchr(s, ' ') + 1; printf("%s", w); What is printed?
- A. world
- B. hello world
- C. hello
- D. w
Correct answer: A. world
strchr returns a pointer to the space, and adding 1 starts the output after it. The string literal's contents are copied into s, so the change is legal.
More C Programming questions
- char a[8] = "abc"; memset(a + 1, 'z', 2); printf("%s", a); What is printed?
- char s[] = "12abc"; char end; long v = strtol(s, &end, 10); printf("%c", end); What is printed?
- char buf[3]; int n = snprintf(buf, 3, "%s", "hello"); printf("%d", n); What is printed?
- char p = "abc"; printf("%d", (p + 3)); What is printed?
- char s[] = "A1b2"; int d = 0; for (int i = 0; s[i]; i++) if (s[i] >= '0' && s[i] <= '9') d++; printf("%d", d); What is printed?
- char buf[10]; int n = sprintf(buf, "%5.2f", 3.14159); printf("%d", n); What is printed?