Question 56Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)

What will be the output of the following C program code if the file "test.txt" is empty,

What will be the output of the following C program code if the file "test.txt" is empty, readable, and exists in the appropriate directory? #include <stdio.h> int main() { FILE *fp = fopen("test.txt", "r"); if (fp == NULL) { printf("Error\n"); } else { printf("Success\n"); fclose(fp); } return 0; }
  1. ASuccess
  2. BNULL
  3. CGarbage value
  4. DError
Show answerHide answer

Correct answer: (A) Success

Explanation

fopen in "r" mode succeeds for an existing readable file even if it is empty, so fp is not NULL and "Success" is printed. Emptiness only matters when reading data.

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

This is question 56 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 2 (1: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.