ProgrammingModerate
printf("%s", "abc" + 1); What is printed?
- A. abc
- B. bc
- C. b
- D. c
Correct answer: B. bc
The string literal decays to a pointer, and adding 1 starts the output at b.
More C Programming questions
- char name[] = "Bob"; char p = name; printf("%c%c", p[0], (p + 2)); What is printed?
- char buf[] = "ab"; buf[2] = 'c'; printf("%zu", sizeof buf); What is printed?
- char s[3] = "ab"; printf("%zu", sizeof s); What is printed?
- char a = "xy"; char b = a; b[0] = 'z'; printf("%s", a); What is printed?
- char buf[8] = "12"; int n = strlen(buf); printf("%d %d", n, (int)sizeof buf - n); What is printed?
- char z[6] = "ab0cd"; printf("%zu", strlen(z)); What is printed?