Pages

Friday, February 9, 2024

C File Management MCQs Set 2

C File Management MCQs Set 2

1. What is the correct way to check if a file was opened successfully after using fopen()?
(a) if (fopen(file_name, "mode") == NULL) { ... }
(b) if (file_pointer != NULL) { ... }
(c) if (errno == 0) { ... }
(d) None of the above

2. Which function closes a file in C?
(a) fclose(file_name)
(b) close(file_pointer)
(c) close(file_name)
(d) Both (a) and (b)

3. Which function reads a single character from a file?
(a) getchar()
(b) getc(file_pointer)
(c) fscanf(file_pointer, "%c")
(d) All of the above

4. How can you determine the current position (read/write pointer) within a file?
(a) ftell(file_pointer)
(b) fseek(file_pointer, 0, SEEK_CUR)
(c) fgetc(file_pointer)
(d) Both (a) and (b)

5. Which function closes an open file?
(a) close(file)
(b) fclose(file)
(c) terminate(file)
(d) destroy(file)

6. What does the EOF macro represent?
(a) End of File
(b) End of Stream
(c) End of Text
(d) End of Function

7. How do you check if a file has been opened successfully?
(a) if (file != NULL)
(b) if (file != EOF)
(c) if (file > 0)
(d) if (file < 0)

>>> Here is your answers


No comments:

Post a Comment