This set of C Multiple Choice Questions & Answers (MCQs) focuses on “File Operations – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. Which one of the following is correct syntax for opening a file.
a) FILE *fopen(const *filename, const char *mode)
b) FILE *fopen(const *filename)
c) FILE *open(const *filename, const char *mode)
d) FILE open(const*filename)
View Answer
Explanation: fopen() opens the named file, and returns a stream, or NULL of the attempt fails.
2. What is the function of the mode ‘ w+’?
a) create text file for writing, discard previous contents if any
b) create text file for update, discard previous contents if any
c) create text file for writing, do not discard previous contents if any
d) create text file for update, do not discard previous contents if any
View Answer
Explanation: w+ is a mode used to open a text file for update (i. e., writing and reading), discard previous contents if any.
3. If the mode includes b after the initial letter, what does it indicates?
a) text file
b) big text file
c) binary file
d) blueprint text
View Answer
Explanation: If the mode consists of letter b after the first letter as in, “rb” or “w+b”, it indicates binary file.
4. fflush(NULL) flushes all ____________
a) input streams
b) output streams
c) previous contents
d) appended text
View Answer
Explanation: fflush(FILE *stream) – fflush() causes any buffered but unwritten to be written on an Output stream. On an input stream, the effect is undefined. fflush(NULL) flushes all output streams.
5. _____removes the named file, so that a subsequent attempt to open it will fail.
a) remove(const *filename)
b) remove(filename)
c) remove()
d) fclose(filename)
View Answer
Explanation: remove(const *filename) removes the named file, so that a subsequent attempt to open it will fail. It returns non-zero of the attempt fails.
6. What is the function of FILE *tmpfile(void)?
a) creates a temporary file of mode “wb+”
b) creates a temporary file of mode “wb”
c) creates a temporary file of mode ” w”
d) creates a temporary file of mode “w+”
View Answer
Explanation: A temporary file is created by tmpfile() function of mode “wb+” that will be automatically removed when closed or when the program terminates normally.
7. What does tmpfile() returns when it could not create the file?
a) stream and NULL
b) only stream
c) only NULL
d) does not return anything
View Answer
Explanation: tmpfile() returns a stream or NULL if it could not create the file.
8. Choose the right statement for fscanf() and scanf()
a) fscanf() can read from standard input whereas scanf() specifies a stream from which to read
b) fscanf() can specifies a stream from which to read whereas scanf() can read only from standard input
c) fscanf() and scanf() has no difference in their functions
d) fscanf() and scanf() can read from specified stream
View Answer
Explanation: The fscanf() is similar to the scanf() function, except that the first argument of fscanf() specifies a stream from which to read whereas scanf() can read from standard input.
9. EOF is an integer type defined in stdio. hand has a value ____________
a) 1
b) 0
c) NULL
d) – 1
View Answer
Explanation: EOF is an integer type defined in stdio. hand has a value – 1.
10. fwrite() can be used only with files that are opened in binary mode.
a) true
b) false
View Answer
Explanation: fwrite() can be used to write characters, integers, or structures to a file. However, fwrite() can be used only with files opened in binary mode.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for C Internship
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs
- Buy C Books
- Apply for Computer Science Internship