Which of the following file-type arguments is used in fopen() library function…
2017
Which of the following file-type arguments is used in fopen() library function to open a new file for both reading and writing and destroys the file if a file with the specified file-name already exists in the current directory?
- A.
"w"
- B.
"w+"
- C.
"a+"
- D.
"r+"
Attempted by 94 students.
Show answer & explanation
Correct answer: B
The "w+" mode opens a file for both reading and writing. If the file already exists, its contents are completely destroyed (truncated to zero length). If the file does not exist, a new empty file is automatically created.
Thus, the correct option is B.