Skip to content
Related Articles

Related Articles

ISRO | ISRO CS 2009 | Question 42
  • Last Updated : 06 Jun, 2018

Substitution of values for names (whose values are constants) is done in
(A) Local optimization
(B) Loop optimization
(C) Constant folding
(D) Strength reduction


Answer: (C)

Explanation: Constant folding is the process of recognizing and evaluating constant expressions at compile time rather than computing them at runtime.

Example: x = 256 * 256 * 256;

Most modern compilers would not actually generate two multiply instructions and a store for this statement. Instead, they identify constructs such as these and substitute the computed values at compile time (in this case, 16777216). The resulting code would load the computed value and store it rather than loading and multiplying several values.

Example:
int a = 30;
int b = 10
int c;
c = b * 4;    // replace b by 10
if (c > 10) {
c = c - 10;
 }
return c * (60 / a);  // (60 / a is replaced with 2)

So, option (C) is correct.


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :