Order PDF of any content from our website with a little minor Fee to donate for hard work. Online MCQs are fully free but PDF books are paid. For details: contact whatsapp +923028700085 Important notes based PDF Books are available in very little price, starting from 500/-PKR; Order Now: contact whatsapp +923028700085

VU Past Papers CS201-Most Importants MCQs on Random and Sequential File Handling in C++

Q#1: What is the focus of the current lecture?
(A) Random Access Files
(B) File Handling
(C) Sequential Access Files
(D) Efficient File Reading
Answer: (B) File Handling

Q#2: In File Handling, which function is used to open files?
(A) close()
(B) open()
(C) read()
(D) write()
Answer: (B) open()

Q#3: What is the default mode for opening a file using ifstream?
(A) ios::in
(B) ios::out
(C) ios::app
(D) ios:ate
Answer: (A) ios::in

Q#4: What is the consequence of opening a file in ofstream with ios::trunc?
(A) Appends data to the end
(B) Destroys previous contents
(C) Opens for reading
(D) Truncates file size
Answer: (B) Destroys previous contents

Q#5: How is a file opened for writing at random positions forward and backward?
(A) ios::in
(B) ios::out
(C) ios:ate
(D) ios::app
Answer: (C) ios:ate

Q#6: Which function is used to determine the current get position of the file pointer while reading?
(A) tellg()
(B) tellp()
(C) seekg()
(D) seekp()
Answer: (A) tellg()

Q#7: What is the purpose of the getline() function?
(A) Read one character at a time
(B) Read one line at a time
(C) Delete file contents
(D) Move the file pointer
Answer: (B) Read one line at a time

Q#8: What type of files are Sequential Access Files?
(A) Binary files
(B) Text files
(C) Character files
(D) Executable files
Answer: (B) Text files

Q#9: Which function is used to move forward or backward within a file?
(A) tellg() and tellp()
(B) getline()
(C) seekg() and seekp()
(D) open() and close()
Answer: (C) seekg() and seekp()

Q#10: How does ios:ate affect file positioning?
(A) Positions at the beginning
(B) Positions at the end
(C) Positions randomly
(D) Positions at the current position
Answer: (B) Positions at the end

Q#11: What is the consequence of using ios::app when opening a file?
(A) Destroys previous contents
(B) Appends data at the end
(C) Opens for reading
(D) Truncates file size
Answer: (B) Appends data at the end

Q#12: In File Handling, what does close() function do?
(A) Reads from a file
(B) Writes to a file
(C) Opens a file
(D) Closes a file
Answer: (D) Closes a file

Q#13: What does seekg() do?
(A) Opens a file for reading
(B) Moves the file pointer
(C) Appends data to the end
(D) Reads one line at a time
Answer: (B) Moves the file pointer

Q#14: How is sequential access defined in file handling?
(A) Writing randomly
(B) Writing in a sequence
(C) Reading one line at a time
(D) Reading in reverse order
Answer: (B) Writing in a sequence

Q#15: What is the consequence of using ios::trunc when opening a file?
(A) Appends data at the end
(B) Destroys previous contents
(C) Opens for reading
(D) Truncates file size
Answer: (B) Destroys previous contents

Q#16: What type of stream is used for reading from a file character by character?
(A) cout
(B) cin
(C) ifstream
(D) ofstream
Answer: (C) ifstream

Q#17: How is data copied from one file to another in the provided example?
(A) Using getline()
(B) One character at a time
(C) Using seekg()
(D) Using tellg() and tellp()
Answer: (B) One character at a time

Q#18: What is the purpose of using ios::in when opening a file?
(A) Destroys previous contents
(B) Opens for reading
(C) Appends data at the end
(D) Truncates file size
Answer: (B) Opens for reading

Q#19: When using getline(), what character is added at the end of the line?
(A) Space
(B) Comma
(C) Null character (‘\0’)
(D) Period
Answer: (C) Null character (‘\0’)

Q#20: What does seekp() function do?
(A) Determines the next position to write a character
(B) Opens a file for reading
(C) Reads one line at a time
(D) Moves forward or backward within a file
Answer: (A) Determines the next position to write a character

Contents Copyrights Reserved By T4Tutorials