Vidyalelo
C Programming · Q252

C Fundamentals

Programming · C Programming · question 252

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
Answer
B.
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