This behavior is undefined and completely depends on the virtual memory scheme that the operating system organized for this process. Typically, you can:
- access some gibberish that belongs to your virtual address space but has no meaning or
- tries to access the limited memory address, in which case the memory display hardware causes a page error, and the OS decides whether to tear off your process or allocate more memory.
If someints is an array on the stack and the last variable declared, you are likely to get some gibberish from the top of the stack or (very unlikely) cause a page error that can either allow the OS to resize the stack or kill your process using SIGSEGV .
Imagine that you declared a single int right after your array:
int someints[100]; int on_top_of_stack = 42; std::cerr << someints[100] << std::endl;
Then, most likely, the program should print 42 , if the compiler somehow does not order the order of declarations on the stack.
Blagovest buyukliev
source share