ccplusplus.com
Learn C, C++ Concepts
Thursday, February 2, 2012
integer overflow example c++
/************************************************************************* * File : interger-overflow.cpp * Author : Saurabh Gupta * Desc : integer overflow example c++ * Source : http://www.ccplusplus.com/p/c_15.html * Created : 11:09 PM Thursday, February 02, 2012 *************************************************************************/ #include
using namespace std; int main() { unsigned short x = 65535; // largest 2-byte unsigned value possible cout << "x was: " << x << endl; x = x + 1; // We assumed for 65536, but we get overflow here ! cout << "x is now: " << x << endl; } /* * OUTPUT * [sgupta@rhel6x86 interger-overflow]$ c++ interger-overflow.cpp -o interger-overflow [sgupta@rhel6x86 interger-overflow]$ ./interger-overflow x was: 65535 x is now: 0 [sgupta@rhel6x86 interger-overflow]$ */
1 comment:
Anonymous
March 27, 2012 at 3:00 AM
sharinG iZ caRinG...:)
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
sharinG iZ caRinG...:)
ReplyDelete