C++ File Management | Set 2
11. Which of the following is not used to seek file pointer?
a) ios::set
b) ios::end
c) ios::cur
d) ios::beg
Answer: A
Explanation: ios::set is not used to seek file pointer. ios::end is used to seek from the end of the file. ios::curr from the current position. ios::beg from the beginning.
12. Which of the following is the default mode of the opening using the ifstream class?
a) ios::in
b) ios::out
c) ios::app
d) ios::trunc
Answer: A
Explanation: By default, the file is opened in ios::in mode if the file object we are using is of ifstream class.
13. Which of the following is the default mode of the opening using the fstream class?
a) ios::in
b) ios::out
c) ios::in|ios::out
d) ios::trunc
Answer: C
Explanation: By default, the file is opened in ios::in|ios::out mode if the file object we are using is of fstream class.
14. Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p()
b) get_pos()
c) get_p()
d) tell_pos()
Answer: A
Explanation: C++ provides tell_p() function to get the current position of the file pointer in a file.
15. Which function is used to reposition the file pointer?
a) moveg()
b) seekg()
c) changep()
d) go_p()
Answer: B
Explanation: seekg() function is used to reposition a file pointer in a file. The function takes the offset and relative position from where we need to shift out pointer.
16. Which of the following is used to move the file pointer to start of a file?
a) ios::beg
b) ios::start
c) ios::cur
d) ios::first
Answer: A
Explanation: ios::beg is used to reposition the file pointer to the beginning of the file. It is whenever you want to reposition the pointer at the beginning from any point to the start of the file.
17. It is not possible to combine two or more file opening mode in open () method.
a) True
b) False
c) May be
d) None of these
Answer: D
Explanation: False, It is not possible to combine two or more file opening mode in open () method.
18. Which of these is the correct statement about eof() ?
a) Returns true if a file open for reading has reached the next character.
b) Returns true if a file open for reading has reached the next word.
c) Returns true if a file open for reading has reached the end.
d) Returns true if a file open for reading has reached the middle.
Answer: C
Explanation: Returns true if a file open for reading has reached the end is the correct statement about eof().
19. Which of the following true about FILE *fp
a) FILE is a structure and fp is a pointer to the structure of FILE type
b) FILE is a buffered stream
c) FILE is a keyword in C for representing files and fp is a variable of FILE type
d) FILE is a stream
Answer: A
Explanation: fp is a pointer of FILE type and FILE is a structure that store following information about opened file
20. Which of the following methods can be used to open a file in file handling?
a) Using Open ( )
b) Constructor method
c) Destructor method
d) Both A and B
Answer: D
Explanation: Both A and B methods can be used to open a file in file handling.