LearnFrenzy
Sign in Take a free test

C Input / Output · Exercise 1 of 4

C Input / Output Input/Output MCQ

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twelve multiple-choice questions on printf and scanf, their return values, line input, file modes, fseek, feof, text and binary mode and the standard streams. Pick an option to check your answer instantly.

Question 1 Easy

What does scanf() return?

A The number of characters read
B The number of input items successfully assigned, or EOF if input ends first
C Always 0 on success
D The last value read
Question page & discussion
Question 2 Easy

Which conversion reads a value into a double variable with scanf()?

A %f
B %lf
C %d
D %Lf
Question page & discussion
Question 3 Easy

Why was gets() removed from the C standard in C11?

A It was too slow
B It cannot limit the input to the buffer size, so long lines overflow it
C It did not handle newlines
D puts() replaced it
Question page & discussion
Question 4 Easy

When the line fits in the buffer, what does fgets() do with the newline character?

A Discards it
B Keeps it in the buffer, followed by '\0'
C Replaces it with a space
D Leaves it in the input stream
Question page & discussion
Question 5 Easy

What are stdin, stdout and stderr?

A Keywords of the language
B Expressions of type FILE * for streams opened before main() starts
C Integer file numbers 0, 1 and 2
D Functions in stdio.h
Question page & discussion
Question 6 Easy

You want to add log lines to the end of a file, creating it if it does not exist. Which mode?

A "r"
B "w"
C "a"
D "r+"
Question page & discussion
Question 7 Medium

What does fseek(fp, -3L, SEEK_END); do?

A Moves 3 bytes past the end
B Moves the position to 3 bytes before the end of the file
C Moves back 3 bytes from the current position
D It is invalid: offsets cannot be negative
Question page & discussion
Question 8 Medium

When does feof(fp) return a non-zero value?

A As soon as the last byte has been read
B After a read operation has tried to go past the end of the file
C When the file is empty, before any read
D After fclose()
Question page & discussion
Question 9 Easy

Which call correctly opens photo.jpg to read its bytes?

A fopen("photo.jpg", "r")
B fopen("photo.jpg", "rb")
C fopen("photo.jpg", "w")
D fopen(photo.jpg, "rb")
Question page & discussion
Question 10 Medium

In scanf("%*d %d", &x);, what does the * do?

A Takes the field width from an argument, as in printf
B Reads an integer and discards it, so x gets the second integer
C Reads into a pointer
D Makes the conversion optional
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links