Q#1: How can you efficiently read a character from a file in C++?
(A) inputFile.getline()
(B) –
(C) inputFile.read()
(D) inputFile.readline()
Answer: (C) inputFile.read()
Q#2: Which function is used to write a character into a file in C++?
(A) outputFile.putline()
(B) outputFile.write()
(C) –
(D) outputFile.writeline()
Answer: (B) outputFile.write()
Q#3: What is the efficient way of reading and writing to disk in C++?
(A) Using getline() and putline() functions
(B) Using getc() and putc() functions
(C) –
(D) Using readLine() and writeLine() functions
Answer: (B) Using getc() and putc() functions
Q#4: How can you read more than a single byte or a single line from a file in C++?
(A) Using getc() function
(B) Using getline() function
(C) Using readLine() function
(D) –
Answer: (B) Using getline() function
Q#5: What does the term “binary” mean in the context of read() and write() functions?
(A) Reading and writing in character mode
(B) Reading and writing in text mode
(C) line mode
(D) Reading and writing in binary format
Answer: (D) Reading and writing in binary format
Q#6: What is the purpose of the read(arrayname, number of bytes) function in C++?
(A) To read a line from a file
(B) To read a character from a file
(C) To read bytes from a file
(D) To read the entire file
Answer: (C) To read bytes from a file
Q#7: How is the loop used in the program to copy a file more efficient than using getc() and putc() functions?
(A) By reducing the size of the file
(B) By increasing the number of read() function calls
(C) By reducing the number of read() and write() calls
(D) By increasing the number of getc() and putc() calls
Answer: (C) By reducing the number of read() and write() calls
Q#8: What happens if the file length is 25199 bytes in the given solution?
(A) The program will terminate with an error
(B) The program will run indefinitely
(C) The solution will work correctly
(D) The solution will not work
Answer: (C) The solution will work correctly
Q#9: How is copying a file in reverse order achieved in C++?
(A) By using reverseFile() function
(B) By using copyReverse() function
(C) By using reverseCopy() function
(D) By writing it byte by byte
Answer: (D) By writing it byte by byte
Q#10: What does seekg(0, ios::end) do in C++?
(A) Moves the file pointer to the beginning of the file
(B) Moves the file pointer to the end of the file
(C) –
(D) Moves the file pointer to the specified location
Answer: (B) Moves the file pointer to the end of the file
Q#11: Why is it necessary to move two positions back when reading a file in reverse order?
(A) To speed up file reading
(B) To avoid errors in file reading
(C) –
(D) To move to the beginning of the file
Answer: (B) To avoid errors in file reading
Q#12: What is mentioned as a potential drawback of using if statements in file processing?
(A) It consumes less memory
(B) It takes fewer clock cycles
(C) –
(D) It improves file processing speed
Answer: (B) It takes fewer clock cycles
Q#13: In terms of speed, which functions are highlighted for file handling in C++?
(A) getline() and putline()
(B) getc() and putc()
(C) –
(D) readLine()
Answer: (B) getc() and putc()
Q#14: What is the benefit of using sizeof() function when writing data into a file in C++?
(A) It reduces the size of the file
(B) It increases the speed of file processing
(C) It improves file readability
(D) Independence from compiler-specific representations
Answer: (D) Independence from compiler-specific representations
Q#15: How is the internal representation of integers affected when writing them into a file using write() function?
(A) It remains the same as on the screen
(B) It becomes more like the internal representation, not what is seen on the screen
(C) It becomes a human-readable format
(D) It becomes compressed
Answer: (B) It becomes more like the internal representation, not what is seen on the screen
Q#16: What is the suggested way to find the size of a data type in C++?
(A) Use a magic number
(B) Use the sizeof() function
(C) –
(D) Use a predefined constant
Answer: (B) Use the sizeof() function
Q#17: What is the purpose of the program that writes integers into a file using the write() function?
(A) To write integers in reverse order
(B) –
(C) To write integers in binary format
(D) To write integers using getc() function
Answer: (C) To write integers in binary format
Q#18: What should be done to find integers inside a file written using write() function in C++?
(A) Use the getline() function
(B) Use the readLine() function
(C) Open the file in notepad and inspect its contents
(D) Use the read() function
Answer: (D) Use the read() function
Q#19: What is suggested to experiment with using the read() function in C++?
(A) Write character data into a file
(B) Write integers into a file
(C) –
(D) Use the putc() function
Answer: (B) Write integers into a file
Q#20: What is the recommended approach for determining the size of variables passed to the write() function?
(A) Use magic numbers
(B) Use predefined constants
(C) –
(D) Estimate based on data content
Answer: (B) Use predefined constants