Question 34Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

#include <stdio.h> int main() {

#include <stdio.h> int main() { FILE *file = fopen("input.txt", "r"); int value; fscanf(file, "%d", &value); fseek(file, 0, SEEK_SET); fscanf(file, "%d", &value); fclose(file); printf("%d\n", value); return 0; } What will be the output of the code if input.txt contains 42?
  1. AUndefined behavior
  2. B42
  3. CEOF
  4. DIt depends on the system
Show answerHide answer

Correct answer: (B) 42

Explanation

The first fscanf reads 42. fseek(file, 0, SEEK_SET) moves back to the start, so the second fscanf reads 42 again, and 42 is printed.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

This is question 34 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM). 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.