edited by
591 views
0 votes
0 votes
Consider the following functions f() and g().

f(){                              g(){
w=5;                              z=w+1;
w=2*z+2;                          z=3*z-w;
}                                 print(z);
                                  }

We start with $w$ and $z$ set to $0$ and execute $f()$ and $g()$ in parallel—that is, at each step we either execute one statement from $f()$ or one statement from $g()$. Which of the following is not a possible value printed by $g()$ ?

  1. $-2$
  2. $-1$
  3.    $2$
  4.    $4$
edited by

2 Answers

1 votes
1 votes

option c. 2 is not printed by the above code.

f()
{
    w = 5;        Line 1
    w = 2*Z+2;    Line 2 
}
g()
{
    Z = W+1;      Line 3
    Z = 3Z - W;   Line 4
    printf(Z);    Line 5
    
}

Case1: 1-3-2-4-5 This sequence will give output as 4.

Case 2: 3-1-4-5-2 This will give -2 as output.

Case 3: 3-1-2-4-5 This will give -1 as output.

  1. CMI 2010
  2. CMI 2012
  3. gate 2015

 

edited by
Answer:

Related questions