Q.Which of the following mode keeps the file offset position at the end of the file?
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Mode a (append) keeps the file offset position at the end of the file, ensuring all writes happen after existing content.
When working with files in programming, the mode you choose determines not just whether you can read or write, but also where the file pointer starts and how the existing content is treated. Understanding these distinctions is essential for handling data correctly.
The r mode opens a file for reading only. The file pointer sits at the beginning, ready to read from the start. You cannot write in this mode, and if the file doesn't exist, you'll get an error. It's purely for consumption of existing data.
The r+ mode opens a file for both reading and writing. The file pointer again starts at the beginning. This means if you write immediately, you'll overwrite existing content from the start unless you explicitly move the pointer. The file must already exist, or the operation fails. It's a two-way mode but begins at the top.
The w mode opens a file for writing. Here's the crucial behavior: it truncates the file, meaning any existing content is wiped out the moment you open it. The file pointer is at the beginning of what is now an empty (or newly created) file. If the file didn't exist, it gets created. This mode is destructive by design. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.