ProgrammingVery hard
char a[20], b[20]; /* stdin: "hi there\nnext\n" */ scanf("%s", a); fgets(b, sizeof b, stdin); What is stored in b?
- A. a space, then 'there', then a newline
- B. 'there' then a newline
- C. 'hi there' then a newline
- D. 'next' then a newline
Correct answer: A. a space, then 'there', then a newline
scanf with %s stops at the first whitespace, leaving the space that follows 'hi' in the input. fgets then reads from that space up to the newline.
More C Programming questions
- char w[] = "ab", z[2] = "ab"; printf("%zu", sizeof w + sizeof z); What is printed?
- For a string s of length up to 2 x 10^5 stored in a char array, which in-place reversal is correct and fast enough?
- What is the value of sizeof("hello") in C?
- char buf[] = "abcn"; buf[strcspn(buf, "n")] = '0'; printf("%zu", strlen(buf)); What is printed?
- Why must the result of getchar() be stored in an int rather than a char?
- Which call reads a line into char buf[100] safely?