Expecting Stack overflow error?

Hi,

After not programming for sometimes I decided to program a small application. But I have some trouble according to what I remember and re-checking arrays online. I don't understand how the code I wrote below is possible, shouldn't give a stack overflow error or something to that extent? Instead it gives me the value of 3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "stdafx.h"
#include<iostream>

int _tmain(int argc, _TCHAR* argv[])
{
int arr2 [2];

arr2 [3] = 3;
  
 std:: cout << arr2[3];
 std:: cin.sync();
 std :: cin.get();
 return 0;

}


Any help is Appreciated.
Nope, that's simply undefined behaviour
Topic archived. No new replies allowed.