I know that EOF
and '\0'
are of type integers, but if so shouldn't they have a fixed value?
I printed both and got -1 for EOF
and 0 for '\0'
. But are these values fixed?
I also had this
int a=-1;
printf("%d",a==EOF); //printed 1
Are the value for EOF
and '\0'
fixed integers?
EOF
is a macro which expands to an integer constant expression with type int
and an implementation dependent negative value but is very commonly -1.
'\0'
is a char
with value 0 in C++ and an int
with the value 0 in C.
The reason why printf("%d",a==EOF);
resulted in 1
was because you didn't assign the value EOF
to a
. Instead you checked if a
was equal to EOF
and since that was true (a == -1 == EOF
) it printed 1
.