Skip to content
Related Articles

Related Articles

GATE | GATE-CS-2006 | Question 60

View Discussion
Improve Article
Save Article
  • Last Updated : 17 Sep, 2021

Consider the following C code segment.

for (i = 0, i<n; i++)
    for (j=0; j<n; j++)
        if (i%2)
            x += (4*j + 5*i);
            y += (7 + 4*j);

Which one of the following is false?
(A) The code contains loop invariant computation
(B) There is scope of common sub-expression elimination in this code
(C) There is scope of strength reduction in this code
(D) There is scope of dead code elimination in this code

Answer: (D)

Explanation: Question asks about false statement

4*j is common subexpression elimination so B is true.

5*i can be moved out of inner loop so can be i%2. 
Means, A is true as we have loop invariant computation.

Next, 4*j as well as 5*i can be replaced with a = - 4;
before j loop then a = a + 4; where 4*j is computed,
likewise for 5*i. C is true as there is scope of strength 

By choice elimination, we have D.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!