C MCQ Questions - File Handling
This section focuses on the "File Handling" in C programming. These C MCQ Questions should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which of the following true about FILE *fp
A. FILE is a keyword in C for representing files and fp is a variable of FILE type.
B. FILE is a stream
C. FILE is a buffered stream
D. FILE is a structure and fp is a pointer to the structure of FILE type
View Answer
Ans : D
Explanation: fp is a pointer of FILE type and FILE is a structure that store following information about opened file.
2. Which of the following mode argument is used to truncate?
A. a
B. w
C. f
D. t
View Answer
Ans : B
Explanation: None
3. The first and second arguments of fopen() are
A. A character string containing the name of the file & the second argument is the mode
B. A character string containing the name of the user & the second argument is the mode
C. A character string containing file pointer & the second argument is the mode
D. None of the mentioned
View Answer
Ans : A
Explanation: None.
4. FILE is of type ______
A. int type
B. char * type
C. struct type
D. None of the mentioned
View Answer
Ans : C
Explanation: It is what is typically termed an opaque data type, meaning it's typically declared as a simple structure, and then internally in the OS libraries the FILE pointer is cast to the actual date-type of the data-structure that the OS will use access data from a file. A lot of these details are system-specific though, so depending on the OS, the definition may differ.
5. fseek() should be preferred over rewind() mainly because
A. rewind() doesn't work for empty files
B. rewind() may fail for large files
C. In rewind, there is no way to check if the operations completed successfully
D. All of the above
View Answer
Ans : C
Explanation: The rewind function sets the file position indicator for the stream pointed to by stream to the beginning of the file.
6. FILE reserved word is?
A. A structure tag declared in stdio.h
B. One of the basic datatypes in c
C. Pointer to the structure defined in stdio.h
D. It is a type name defined in stdio.h
View Answer
Ans : D
Explanation: It is a type name defined in stdio.h
7. For binary files, a ___ must be appended to the mode string.
A. "b"
B. "B"
C. "binary"
D. "01"
View Answer
Ans : A
Explanation: None
8. Which of the following statements about stdout and stderr are true?
A. Same
B. Both connected to screen always.
C. Both connected to screen by default.
D. stdout is line buffered but stderr is unbuffered.
View Answer
Ans : C
Explanation: None
9. Which type of files can't be opened using fopen()?
A. .txt
B. .bin
C. .c
D. None of the above
View Answer
Ans : D
Explanation: None
10. When a C program is started, O.S environment is responsible for opening file and providing pointer for that file?
A. Standard input
B. Standard output
C. Standard error
D. All of the above
View Answer
Ans : D
Explanation: None
Also check :
Discussion