ProgrammingHard
char buf[3] = {'a', 'b', 'c'}; printf("%.2s", buf); What is printed?
- A. abc
- B. a
- C. ab
- D. ba
Correct answer: C. ab
The precision .2 limits the output to two characters, so the array's missing terminator is never reached.
More C Programming questions
- char s[10] = "xyz"; strcpy(s + 1, "ab"); printf("%s", s); What is printed?
- 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?