0xC0000005: 0x06AC2373 Access violation occurred while recording location

-1

Hello everyone I found a serious problem in visual studio.

I coded a program with language c ++, environment [visual studio 2019].

I declared vector<long long> vec_fibo , long long arr[50] = {} in heap space.

And then I declared two functions.

ll fibonacci(int idx) {
if (idx <= 2) {
    return arr[idx] = 1;
}
if (arr[idx]) {
    return arr[idx];
}
return arr[idx] = fibonacci(idx - 1) + fibonacci(idx - 2);}

void push_fibo(int value, int idx) {
if (value < arr[idx]) {
    return;
}
if (value == 0) {
    return;
}

vec_fibo.push_back(arr[idx]);
for (int i = idx-1; i >= 1; i++) {
    push_fibo(value - arr[i], i);
}}

I think everything is fine... but the

vec_fibo.push_back(arr[idx])

has problem. Runtime Error occured.

I'd never know why the problem was occured.

The main code same below.

ios_base::sync_with_stdio(false);   
cin.tie(0);
cout.tie(0);
cin >> T;
fibonacci(48);
while (T--) {
    int n;
    cin >> n;
    int start_idx = 0;
    for (int i = 1; i < 48; i++) {
        if (arr[i] > n) {
            start_idx = i;
            break;
        }
    }
    push_fibo(n, start_idx-1);
    sort(vec_fibo.begin(), vec_fibo.end());
    for (int i = 0; i < vec_fibo.size(); i++) {
        cout << vec_fibo[i] << ' ';
    }
    cout << '\n';
    init();
}

If i remove the line "fibonacci(48)", runtime error was not occured. But I never realized why the program was going well..

Edit:: The input is

4 100 200 12345 1003

and the Anser is 3 8 89 1 55 144 1 34 377 987 10946 3 13 987

I want to show the numbers makes N with fibonacci numbers.

enter image description here

The above is debug picture. First push_fibo function call Screenshot.

c++
visual-studio
memory
vector
push-back
asked on Stack Overflow Jan 22, 2021 by 안은노 • edited Jan 22, 2021 by 안은노

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0