Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - File Handling
What will be the output of the following PHP code?
$file = fopen('test.txt', 'r');
fseek($file, 3);
echo ftell($file);
A3
B0
C1
DError
Step-by-Step Solution
Solution:
  1. Step 1: Move pointer to position 3

    fseek($file, 3); moves the pointer 3 bytes from the start (default SEEK_SET).
  2. Step 2: Check pointer position with ftell()

    ftell($file) returns current pointer position, which is 3.
  3. Final Answer:

    3 -> Option A
  4. Quick Check:

    fseek + ftell = pointer position 3 [OK]
Quick Trick: ftell() shows pointer after fseek() moves it [OK]
Common Mistakes:
  • Assuming pointer stays at 0
  • Expecting error without reason
  • Confusing fseek offset meaning

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes