The value of z after the execution of the following program is
void f(int x) {
staticint z;
z=z+x;
}
int main() {
int y=10;
fork();
f(y);
return 0;
1.30
2.20
3.40
4. 10
Prince Sindhiya 10 should be the correct answer. Fork is implemented using copy on write mechanism. each child will have its own address space. So updation by one process won't affect other. please read this copy on write method from galvin. :)
As the function $f(10)$ is called $4$ times and the variable $z$ is static.
Initially, $z=0$
On first function call, $z=0+10=10$
On second call, $z=10+10=20$
On third call, $z=20+10=30$
On fourth call, $z=30+10=40$
So, answer should be $40$