Table Of Contents
Previous Section Next Section

Program 14: Shifty Programming

The programmer knows that shifting left is the same as multiplying by a power of two. In other words:

The programmer uses this trick to quickly perform a simple calculation. But something goes wrong:

  1 /************ *********** ************ **********
  2  * Simple syntax testing.                       *
  3  ************************************************/
  4 #include <iostream>
  5
  6 int main(void)
  7 {
  8     int x,y;    // Two numbers
  9
 10     x = 1;
 11
 12     y = x<<2 + 1; // x<<2 = 4 so y = 4+1 = 5
 13     std::cout << "Y=" << y << std::endl;
 14     return (0);
 15 }

(Next Hint 266. Answer 49.)

Table Of Contents
Previous Section Next Section