If you look at the generated assembly code, you will see that printf ("%s\n",…)
has been optimized by the compiler into a call to puts
, whereas other format strings do not lend themselves to this trick.
It so happens that on your platform, the printf
function detects null pointers and kindly avoids to crash, whereas the puts
function doesn't.
The distinction doesn't matter: it is undefined behavior to pass a null pointer to printf
for %s
. Do no do it ever, even if, on your particular compilation platform, you were lucky the second time.