I don't understand why the answer to question 20 was D, rather than C, is anyone able to explain?
Thank you :)
(20) Consider the following C code:
*
void function(void)
{
fork();
fork();
printf("hello world\n");
}
*
If the above code executes successfully, which of the following statements will always be
true?
A. The output "hello world" will be printed once.
B. The output "hello world" will appear exactly twice, on two separate lines.
C. The output "hello world" will appear exactly four times, on four separate lines.
D. The form of the output cannot be determined from the above code.
I don't understand why the answer to question 20 was D, rather than C, is anyone able to explain?
Thank you :)
(20) Consider the following C code:
*
void function(void)
{
fork();
fork();
printf("hello world\n");
}
*
If the above code executes successfully, which of the following statements will always be
true?
A. The output "hello world" will be printed once.
B. The output "hello world" will appear exactly twice, on two separate lines.
C. The output "hello world" will appear exactly four times, on four separate lines.
D. The form of the output cannot be determined from the above code.
I don't know what Chris had mind, it could be a trick question (note the 'always be true'). Suppose I write a complete C code with a main() and do not call this function?
well, not really sure about this either, but in my opinion it really comes down to technicality, since after the fork, the code doesn't terminate, so we can either call fork() again somewhere outside the function, or call the function more than one time