#include <iostream>

using namespace std;



int main()

{

    int length = 5;

    cin >> length;

    int* array = new int[length]();    

    array[0] = 1;

    array[1] = 2;

    for (int i = 0; i < length; ++i)

    {

        cout << (uintptr_t) & array[i] << endl;

        cout << array[i] << endl;

    }

    delete[] array;

}

위 처럼 치면 버퍼 오버런이 발생했다고 하는데, 정상 작동은 되네요.

여기서 궁금한 점은 

첫째로, 버퍼 오버런이 발생해도 정상 작동 되는데, 위처럼 해도 되는지, 안 된다면 어떤 문제가 발생하는 지 알고 싶습니다.

둘째로, cin >>으로 변수를 넣어(동적할당의 방식으로) 그만큼의 메모리 크기를 할당하는 다른 방법이 없는 지 궁금합니다.

viewimage.php?id=3dafdf21f7d335ab67b1d1&no=24b0d769e1d32ca73dec87fa11d0283123a3619b5f9530e1a1306968e3deca0e73a49f63bdf430be303ebb422619896c5388ee1ecf1a599e750f7d75a662330e968f6cb0b571