I heard that you have to include ......


I heard that you have to #include before calling printf. Why?

✍: Guest


So that a proper prototype for printf will be in scope.
A compiler may use a different calling sequence for functions which accept variable-length argument lists. (It might do so if calls using variable-length argument lists were less efficient than those using fixed-length.) Therefore, a prototype (indicating, using the ellipsis notation ``...'', that the argument list is of variable length) must be in scope whenever a varargs function is called, so that the compiler knows to use the varargs calling mechanism.

2016-01-08, 673👍, 0💬