Question:medium

Which method moves a file pointer to the nth character with respect to r position?

Updated On: Jan 16, 2026
  • fp.seek(r)
  • fp.seek(n)
  • fp.seek(n, r)
  • seek(n, r).fp
Show Solution

The Correct Option is C

Solution and Explanation

In Python and similar programming languages, the seek() method is utilized for file pointer manipulation. It allows repositioning the pointer to a specific byte offset within a file. The seek() method accepts arguments specifying the offset and a reference point.

The call signature fp.seek(n, r) repositions the file pointer by n bytes relative to a reference position r. The value of r determines the starting point for the offset:

  • 0 signifies the beginning of the file.
  • 1 indicates the current pointer position.
  • 2 denotes the end of the file.

File pointer movement is a fundamental aspect of file I/O, enabling read and write operations at arbitrary file locations. Among the options presented, only fp.seek(n, r) correctly demonstrates the seek method's usage with both offset (n) and reference (r) arguments, making it the appropriate syntax for repositioning the file pointer based on a specified offset from a reference position.

Was this answer helpful?
0