ProgrammingVery hard
char buf[10]; strncpy(buf, "abc", 10); int zeros = 0; for (int i = 0; i < 10; i++) if (buf[i] == 0) zeros++; printf("%d", zeros); What is printed?
- A. 6
- B. 8
- C. 1
- D. 7
Correct answer: D. 7
strncpy copies 'abc' and then pads the remaining 7 bytes with zeros, so there are 7 zero bytes in total.
More C Programming questions
- printf("%zu", sizeof("a" "bc")); What is printed?
- char c = 'a' + 25; printf("%c", c); What is printed on an ASCII system?
- int r = strcmp("abc", "abd"); What can be said about r according to the C standard?
- const char s = "abcabc"; printf("%ld", (long)(strstr(s, "ca") - s)); What is printed?
- char d[4] = "abc"; printf("%zu", sizeof d - strlen(d)); What is printed?
- char s[] = "Hello"; for (char p = s; p; p++) if (p >= 'a' && p <= 'z') p -= 32; printf("%s", s); What is printed?