ProgrammingHard
char line[6]; fgets(line, sizeof line, stdin); /* stdin holds the text 12345678 followed by a newline */ printf("%zu", strlen(line)); What is printed?
- A. 6
- B. 4
- C. 8
- D. 5
Correct answer: D. 5
fgets stores at most five characters plus the terminator, so the string is 12345 with length 5.
More C Programming questions
- 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?
- char a[] = "Level"; int pal = 1; for (int i = 0, j = 4; i < j; i++, j--) if (tolower(a[i]) != tolower(a[j])) pal = 0; printf("%d", pal)…
- printf("[%-6s|]", "ab"); What is printed?