Integer memory overflow?

Hey all, I was wondering if it was possible to overflow memory after an integer input from the following code:

1
2
3
int n;
cout << "Enter the size of the array you wish to input: ";
cin >> n;


Tests have shown that any number larger than max int makes n = max int, but what happens to the memory cells after n's address?
no, you can't break the program by entering a ridiculously large number.
of couse!
a integer is 4byte
if you input a number lager 4 byte.
it is overplowing.
Last edited on
When an integer overflows, the most significant bits that don't fit are discarded, so memory corruption can never occur (however, there's no overflow here - when reading a value with cin and an overflow would occur, the largest possible value is used instead, as you noticed).
Last edited on
Topic archived. No new replies allowed.