
What is displayed to the terminal by the following c code: int x = 0;//global variable int y – 2;//global variable void main() { if (fork() = = 0) { y – l; > else { x – 1; > if (x = = 1) { printf(“% dn”, y); } } 2 0 1 3
Expert Answer
Answer is 2(Option A)
In the above code, a child process is created, fork() returns 0 in the child process and positive integer to the parent process.
So if loop not executed else loop execute x is initialized with 1. and then if(x==1) then y printed. Y is initialized with 2.
So the answer is: 2