14th Chapter Solved Exercise MCQs Of ICS Second Year Computer Science
14th Chapter Solved Exercise MCQs Of ICS Second Year Computer Science. Each question includes the correct answer and a brief explanation. It’s designed to help you study, prepare for exams, and understand key concepts better. Boost your Computer Science knowledge with these practice exercises.
14th chapter solved MCQs with explanation
1. A file is stored in:
a) RAM
b) hard disk
c) ROM
d) cache
Explanation: Files are stored on the hard disk because it saves data permanently, unlike RAM, which only keeps data temporarily.
2. Which of the following modes open only an existing file for both reading and writing:
a) “w”
b) “w+”
c) “r+”
d) “a+”
Explanation: The “r+” mode opens an existing file and allows both reading and writing. The “w+” mode creates a new file or clears an existing file, and “a+” opens a file for appending data.
3. Which of the following functions is used to write a string to a file?
a) puts()
b) putc()
c) fputs()
d) fgets()
Explanation: The fputs() function writes a string to a file, while puts() prints to the console, putc() writes a single character, and fgets() reads a string from a file.
4. On successfully closing a file, the fclose() function returns:
a) NULL
b) 0 (zero)
c) 1 (one)
d) FILE pointer
Explanation: The fclose() function returns 0 to indicate that the file was closed successfully. Any other return value usually means there was an error.
5. An array subscript should be:
a) int
b) float
c) double
d) an array
Explanation: An array subscript must be an integer because it represents the position of an element in the array, which is always a whole number.
6. The function fopen() is used to:
a) create a file
b) open a file
c) both a and b
d) none of the above
Explanation: The fopen() function is used specifically to open an existing file or create a new one if it does not exist. It does not only create a file.
7. The mode “r” in the fopen() function is used to:
a) read a file
b) write a file
c) append to a file
d) create a file
Explanation: The “r” mode opens a file for reading only. It does not allow writing or appending.
8. The function fgets() is used to:
a) read a character from a file
b) read a line from a file
c) write a character to a file
d) write a line to a file
Explanation: The fgets() function reads an entire line from a file, not just a single character or a line of text to the file.
9. The function fprintf() is used to:
a) write a formatted string to a file
b) read a formatted string from a file
c) both a and b
d) none of the above
Explanation: The fprintf() function writes a formatted string to a file, similar to how printf() writes to the console.
10. The function fseek() is used to:
a) set the file position indicator
b) get the file position indicator
c) both a and b
d) none of the above
Explanation: The fseek() function sets the position in the file where the next read or write will occur. It does not get the current position, which is done by ftell().
Leave a Reply