Printing the value of EOF
putchar(c)
means to output the character which corresponds to c
(which is a number) in the character encoding in use (usually ASCII).
There is no character which is encoded as EOF
(that's the whole point of EOF
).
The stipulation to "print value of EOF" does not mean "print the character whose code is EOF
" (since there is none). Instead they most likely mean to print the integer with the same value as EOF
on your system.
putchar function prints a character.
But EOF is not a character and is used to indicate the End of a file. So the getchar returns a value which is distinguishable from the character sets so as to indicate there is no more input.
So printing EOF using putchar() wont print any values
printing it as integer
printf("%d",EOF);
gives result -1
try this:
#include <stdio.h>
int main(){
printf("EOF: %d\n", EOF);
}
EOF
is not a printable char as you expected.