Test Series - cpp

Test Number 100/102

Q: By default, all the files in C++ are opened in _________ mode.
A. Text
B. Binary
C. ISCII
D. VTC
Solution: By default, all the files in C++ are opened in text mode. They read the file as normal text.
Q: What is the use of ios::trunc mode?
A. To open a file in input mode
B. To open a file in output mode
C. To truncate an existing file to half
D. To truncate an existing file to zero
Solution: In C++ file handling, ios::trunc mode is used to truncate an existing file to zero length.
Q: Which of the following is the default mode of the opening using the ofstream class?
A. ios::in
B. ios::out
C. ios::app
D. ios::trunc
Solution: By default, the file is opened in ios::out mode if the file object we are using is of ofstream class.
Q: What is the return type open() method?
A. int
B. char
C. bool
D. float
Solution: open() method returns a bool value indicating whether the file is opened or some error has occurred.
Q: Which of the following is not used to seek file pointer?
A. ios::set
B. ios::end
C. ios::cur
D. ios::beg
Solution: 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.
Q: 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
Solution: By default, the file is opened in ios::in mode if the file object we are using is of ifstream class.
Q: 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
Solution: By default, the file is opened in ios::in|ios::out mode if the file object we are using is of fstream class.
Q: 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()
Solution: C++ provides tell_p() function to get the current position of the file pointer in a file.
Q: Which function is used to reposition the file pointer?
A. moveg()
B. seekg()
C. changep()
D. go_p()
Solution: 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.
Q: 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
Solution: 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.

You Have Score    /10