printf buffers I / O before it actually writes data to standard (as @little_birdie mentioned). Buffered I / O refers to the practice of temporarily storing I / O operations in your application (user space) until it is transferred to the kernel, which can be slow. To minimize these so-called system calls, your application will request such memory ahead of time.
Often, some system functions may completely disable this function, or even, perhaps, for a historical system, do not have buffered I / O at all (although I am not familiar with any).
If you want to disable buffering on stdout here (and thus allocate "0" bytes of heap memory), you can request it with setbuf as follows:
#include <stdio.h> int main() { int distance = 100; setbuf(stdout, NULL); printf("You are %d miles away.\n", distance); return 0; }
If you want to know more about this, check out the great Linux Programming Interface.
ลนV - source share