C allows you to call functions without first defining the prototypes. (C++ does not do this.) An implicit prototype for printf
will be defined as follows:
int printf();
Coincidentally, the calling conventions for this implicit prototype matched the actual calling conventions for printf
on your platform.
In general, you cannot count on this working, and there are a large number of cases where it won't work. I recommend enabling compiler warnings to detect implicit prototype declarations so you can fix them (by including the correct header).
Footnote: #include
does not import libraries, it merely pastes files into your source code at compile time. The <stdio.h>
header contains (directly or indirectly) certain prototypes, but the library has to be linked in separately. Since printf
is usually in a library that is linked to programs by default, you usually don't have to do anything to use printf
.