Why does the following code compile?
#include <stdio.h>
int main(void) {
getchar;
}
Why does the following code compile?
#include <stdio.h>
int main(void) {
getchar;
}
The same reason 1;
would compile, getchar
is just an address to a function. The result is evaluated, then discarded. In the language specification, it's called an "expression statement";
Because function names are aliases to function pointers to those functions, which are themselves values much like integers.. This is semantically very similar to
#include <stdio.h>
int main(void) {
42;
}
It is valid but pointless.