Q252
What will be the output of the following C code? #include int main() char c; int i = 0; FILE *file; file = fopen("test.txt", "w+"); fprintf(file, "%c", 'a'); fprintf(file, "%c", -1); fprintf(file, "%c", 'b'); fclose(file); file = fopen("test.txt", "r"); while ((c = fgetc(file)) != -1) printf("%c", c); return 0;
A.
a
AnswerB.
Infinite loop
C.
Depends on what fgetc returns
D.
Depends on the compiler
Answer: Option A
Solution
Answer: Option A
No explanation is given for this question Let's Discuss on Board