edited by
758 views
1 votes
1 votes

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();

fork();

f(y);

return 0;

}

1.30

 

2.20

 

3.40

 

4. 10

edited by

1 Answer

0 votes
0 votes

                                                                

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$

Related questions

0 votes
0 votes
0 answers
1
0 votes
0 votes
1 answer
2
Prince Sindhiya asked Jan 2, 2019
705 views
A full binary tree is a tree in which every node other than the leaves has two children. If there are 600 leaves then total number of leaf nodes are?