MCQ - File Handling in C++ Programming
21. If we have object from ofstream class, then default mode of opening the file is _____
A. ios::in
B. ios::out
C. ios::in|ios::trunc
D. ios::out|ios::trunk
View Answer
Ans : D
Explanation: If we have object from ofstream class, then default mode of opening the file is ios::out|ios::trunk.
22. Which is correct syntax for, position n bytes back from end of fileObject ?
A. FileObject.seekg(ios::end, n);
B. FileObject.seekg(n, ios:end );
C. FileObject.seekg(n, ios::end );
D. FileObject.seekg(ios:end, n);
View Answer
Ans : C
Explanation: FileObject.seekg(n, ios::end ); is correct syntax for, position n bytes back from end of fileObject.
23. When fopen() is not able to open a file, it returns
A. EOF
B. Null
C. Runtime error
D. Compiler dependent
View Answer
Ans : B
Explanation: fopen() returns NULL if it is not able to open the given file due to any of the reasons like file not present, inappropriate permissions, etc.
24. By default, all the files are opened in which of the following mode?
A. Binary Mode
B. Text Mode
C. Sequential Mode
D. Both A and B
View Answer
Ans : B
Explanation: By default, all the files are opened in Text mode
25. How many objects are used for input and output to a string?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : C
Explanation: The stringstream, ostringstream, and istringstream objects are used for input and output to a string.
26. Calling the stream's member function sync() causes an immediate synchronization.
A. Yes
B. NO
C. May Be
D. Can't Say
View Answer
Ans : A
Explanation: Yes, Calling the stream's member function sync() causes an immediate synchronization.
27. Which of the following is not used to seek a file pointer?
A. ios::cur
B. ios::beg
C. ios::end
D. ios::set
View Answer
Ans : D
Explanation: None
28. fseek() should be preferred over rewind() mainly because
A. In rewind, there is no way to check if the operations completed successfully
B. rewind() doesn't work for empty files
C. rewind() does work for empty file
D. All of the above
View Answer
Ans : A
Explanation: None.
29. Which function is used to position back from the end of file object?
A. Seekg
B. Seekp
C. Both seekg & seekp
D. None of the above
View Answer
Ans : A
Explanation: The member function seekg is used to position back from the end of file object.
Also check :
Discussion