Here is my C program :
int main() {
fork();
printf("one ");
fork();
printf("two ");
}
The output is :
one two one two one two one two
However, If I change the code and add a \n
to the print statement :
int main() {
fork();
printf("one\n");
fork();
printf("two\n");
}
The output is :
one
one
two
two
two
two
Or sometimes (the order can change) :
one
two
one
two
two
two
Why is the output 8
words in the first program and 6
in the second?