Skip to main contentSkip to solution

What will be the output after execution of the following commands on a file, consider 'f' as the file pointer?

f.seek(10)

f.read(1)

f.read(1)

f.tell()

Solution

✅ Correct Option: 3

f.seek(10) moves the file pointer to position 10. Each f.read(1) reads one character and moves the pointer forward by 1, so after two reads it is at 10+1+1=1210 + 1 + 1 = 12. f.tell() returns the current pointer position, which is 12.


Option 1: this is the position right after seek(10), before any reads.

Option 2: this is the position after only one read(1).

Option 4: this comes from counting from position 11 or adding an extra read; there are only two reads.

tell() returns the position of the next byte to be read, not the last byte read.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question