Why Does This Not Crash?

it career's Avatar, Join Date: Apr 2007
Go4Expert Member
Hello C/C++ experts,

I write the following code
Code:
int a[10];
int b[10];

//initiliaze all element of array a and b to 0.
a[11]=255;
Neither the program crashes nor the value of b[0] becomes 255
What could be the reason?
DaWei's Avatar, Join Date: Dec 2006
Team Leader
The language doesn't define how those two are related, merely that each is contiguous and that element n+1 is one element higher in memory than element n. If you have a common implementation, inside a function, and that function uses the stack, which it would be stupid to count on, b[11] will write into a[0].

I would suggest that if you want to play with such stuff, get into machine language. You'll find lots of undefined behavior in C/C++ accidentally, no need to go looking for a way to turn a cotton purse into sow's excrement; nor will I, personally, teach you how to write exploits.