Consider the following C program. Assume there are no syntax errors and the…
Consider the following C program. Assume there are no syntax errors and the program executes correctly. Assume the fork system calls succeed. What is the output printed to the screen when we execute the below program? (MCQ)
void main(argc, argv)
{
for(int i = 0; i < 4; i++)
{
int ret = fork();
if(ret == 0)
printf("child %d\n", i);
}
}
- A.
The statement "child i" is printed exactly 4 times for each i from 0 to 3.
- B.
The statement "child i" is printed 8 times for i=0, 16 times for i=1, and so on.
- C.
The statement "child i" is printed 2^i times for i=0 to 3
- D.
None of these
Attempted by 154 students.
Sign up free to check your answer
Sign up freeLoading lesson…