Skip to main contentSkip to solution

Sequence the steps to write data to a file and then read it back:

(A). Write data to the file.

(B). Open the file in w+ mode.

(C). Read the data from the file.

(D). Seek to the beginning of file.

Solution

✅ Correct Option: 4

(B) Open the file in w+ mode. This allows both writing and reading, and creates the file or empties it.

(A) Write data to the file.

(D) Seek to the beginning of the file. After writing, the file pointer is at the end of the data.

(C) Read the data from the file.


Reading without seeking first returns an empty string, because the pointer is still at the end of the file after writing.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question