Why is printf not equivalent to scanf?

c

Solution

You aren't calling the functions and comparing the results, you are comparing the functions themselves, which boils down to comparing the addresses of the functions (function names will convert to function pointers in many contexts, this is one). What you wrote is equal to this:

/* this is the correct signature for main by the way, not `void main()` */
int main(int argc, char **argv) {
    /* compare the address of printf to that of scanf */
    if (&printf == &scanf) {
        printf("hello");
    } else {
        printf("hi");
    }
}

Since `scanf` and `printf` are not the same function they live at a different address so the comparison fails and `hi` is printed.

Problem

I have a program which displays "hi", but I do not understand why. I understand both scanf and printf return the number of characters they read/write but how does it work in this case? ``` void main() { if(printf==scanf) printf("hello"); else printf("hi"); } ```

Original source