Home » C Programming » Input / Output

What will be the output of the program? #include int main() { FILE *fp; unsigned char ch; /* file 'abc.c' contains "This is CuriousTab " */ fp=fopen("abc.c", "r"); if(fp == NULL) { printf("Unable to open file"); exit(1); } while((ch=getc(fp)) != EOF) printf("%c", ch); fclose(fp); printf("\n", ch); return 0; }

Correct Answer: Infinite loop

Explanation:

The macro EOF means -1.


while((ch=getc(fp)) != EOF) Here getc function read the character and convert it to an integer value and store it in the variable ch, but it is declared as an unsigned char. So the while loop runs infinitely.


← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion