The code is as follows:
printf("u"); write(STDOUT_FILENO, "m", 1); printf("d\n");
conclusion: dirt
Can someone explain why the output is printed in this order?
Standard output is buffered by default, which means printf("u")it will put "u"into its buffer until a character fflushor a new character in a line appears . To see the result in order, try the following:
printf("u")
"u"
fflush
printf("u"); fflush(stdout); write(STDOUT_FILENO, "m", 1); printf("d\n");
printf "u" . write . printf "d\n" . - ( , printf , ), .
printf
write
C . printf u , m write, , printf d , , ( , FILE* ), \n , .
u
m
d
FILE*
\n
stderr does not load by default, try the following:
stderr
fprintf(stderr, "u"); write(STDERR_FILENO, "m", 1); fprintf(stderr, "d\n");