CSC231 OverFlow C Program

From dftwiki3
Revision as of 10:18, 22 September 2008 by Thiebaut (talk | contribs) (New page: Back to Weekly Schedule ---- =A C++ Program that overflows= <code><pre> // mulby2.cpp // D. Thiebaut // demonstrates how a compiled language deals with an overflow...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Back to Weekly Schedule


A C++ Program that overflows

// mulby2.cpp
// D. Thiebaut
// demonstrates how a compiled language deals with an overflow.
// check mulby2.py to see how an interpreted language will do.
//
#include <iostream.h>

main() {
  unsigned int x, lastx;

  cout << endl << endl << endl << endl;

  x = 1;
  cout << "x = " << x << endl;

  while ( 1 ) {
    lastx = x;
    x = x * 2;
    if ( x <= lastx ) {
      cout << "last x = " << lastx << endl;
      cout << "x = " << x << endl;
      break;
    }
  }
  cout << endl << endl << endl << endl;
}