This question already has an answer here:
- Why does printf not flush after the call unless a newline is in the format string? 9 answers
Testing the fork function in combination with printf i found some strange behavior
For example, the code:
int main(){
if(fork()==0){
printf("TestString");
}
}
doesn't print out anything, while
int main(){
if(fork()==0) {
printf("TestString\n");
}
}
prints out TestString correctly. Why does printing a new line change the behavior? I suspect it might do something with fflush(), but i am not sure. Could i get and explanation or a link where i can read up on it? Thank you for the answer in advance.
EDITED: The explanation i am looking for is what is actually flushing and why is \n same as flushing.