ProgrammingHard
char s[] = "x\0y"; printf("%s", s); What is printed?
- A. xy
- B. y
- C. x y
- D. x
Correct answer: D. x
The embedded zero ends the string for %s, so only x is printed.
More C Programming questions
- char s[5] = "abc"; printf("%d", s[4]); What is printed?
- printf("%zu", strlen("a b c")); What is printed?
- char buf[16]; sprintf(buf, "%d-%d", 1, 22); printf("%zu", strlen(buf)); What is printed?
- char s[] = "abcd"; int n = strlen(s); for (int i = 0; i < n / 2; i++) { char t = s[i]; s[i] = s[n - 1 - i]; s[n - 1 - i] = t; }…
- char s[] = "a1B2-c"; int n = 0; for (char p = s; p; p++) if (isalpha((unsigned char)p)) n++; printf("%d", n); What is printed?
- char c = 'a' + 1; printf("%c", c); What is printed?