ProgrammingHard
char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); printf("%d %s", n, buf); What is printed?
- A. 5 1234
- B. 5 123
- C. 4 123
- D. 3 123
Correct answer: B. 5 123
The full text 12345 has five characters, so snprintf returns 5. The buffer keeps the first three digits and the terminator.
More C Programming questions
- char s[8] = "ab"; strncat(s, "cdefgh", 2); printf("%zu", strlen(s)); What is printed?
- char line[6]; fgets(line, sizeof line, stdin); / stdin holds the text 12345678 followed by a newline / printf("%zu", strlen(line)); What…
- char buf[7] = "hello"; memmove(buf + 1, buf, 5); printf("%s", buf); What is printed?
- char s[] = "one two three"; int w = 0; for (char t = strtok(s, " "); t; t = strtok(NULL, " ")) w++; printf("%d", w); What is printed?
- int n = 0; sscanf(" 42 abc", " %d", &n); printf("%d", n); What is printed?
- char a[] = "Level"; int pal = 1; for (int i = 0, j = 4; i < j; i++, j--) if (a[i] != a[j]) pal = 0; printf("%d", pal); What is printed?