Question 2

Which of the following file stream function will move the file pointer to Nth record in a binary file F created with the help of objects of class EMP?

  1. AF.tellg(N)
  2. BF.seekp(N)
  3. CF.seekp((N−1)* sizeof(EMP))
  4. DF.seekp(sizeof(EMP)/N)
Show answerHide answer

Correct answer: (C) F.seekp((N−1)* sizeof(EMP))

Explanation

Records are stored one after another, so the Nth record begins after N−1 records, at byte offset (N−1)*sizeof(EMP). seekp() moves the put pointer there; tellg() only reports the current position.

From DSSSB TGT Computer Science Practice Set 5

This is question 2 of DSSSB TGT Computer Science Practice Set 5. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.