ProgrammingModerate
char s[5] = "abcd"; printf("%s", s + 2); What is printed?
- A. cd
- B. abcd
- C. c
- D. ab
Correct answer: A. cd
s + 2 points at the third character, so printing starts at 'c'. The terminator is set by the array size, and the string is still terminated.
More C Programming questions
- char buf[4]; int n = snprintf(buf, sizeof buf, "%c%c%c%c", 'w', 'x', 'y', 'z'); printf("%d %s", n, buf); What is printed?
- char names[] = {"ab", "cde"}; printf("%zu", sizeof names / sizeof names[0]); What is printed?
- for (char c = 'a'; c <= 'e'; c += 2) putchar(c); What is printed?
- char cnt[26] = {0}; cnt['c' - 'a']++; printf("%d", (int)('c' - 'a')); What is printed?
- printf("%s", (char[]){'h', 'i', '0'}); What is printed?
- char a = "ab", b = "ab"; printf("%d", strcmp(a, b) == 0); What is printed?