CBSE Class 12 Computer Science Question 60 of 145

File Handling — Question 21

Back to all questions
21
Question

Question 21

Which of the following command is used to open a file "c:\pat.txt" for writing as well as reading in binary format only ?

  1. fout = open("c:\pat.txt", "w")
  2. fout = open("c:\\pat.txt", "wb")
  3. fout = open("c:\pat.txt", "w+")
  4. fout = open("c:\\pat.txt", "wb+")
Answer

fout = open("c:\\pat.txt", "wb+")

Reason — The syntax to open a file for writing as well as reading in binary format is f = open("c:\\temp\\data.txt", "wb+"). Hence according to this syntax fout = open("c:\\pat.txt", "wb+") format is correct.