Consider the following program mainint child fork int x 5

Consider the following program: main(){int child - fork(); int x = 5; if (child == 0) {x + = 5;} else {child = fork(); x += 10; if (child) {x+=5;}}} How many different copies of the variable x are there? What are their values when their process finishes?

Solution

There is only one copy of the variable x as it is used only in the main function as per the code.

The value of x depends on the value of child.

if value of child is 0 x comes out to be10

else x comes out to be 20.

 Consider the following program: main(){int child - fork(); int x = 5; if (child == 0) {x + = 5;} else {child = fork(); x += 10; if (child) {x+=5;}}} How many d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site