When deleting array: "Process returned -1073740940 (0xC0000374)" Only with certain numbers

  arrays, c++, codeblocks, dynamic-arrays

The program returns the user N number of odd squares starting from 1.

From numbers 5-10 and then 20, (I didn’t go further) when deleting array A it crashes with the error message: "Process returned -1073740940 (0xC0000374)". Which is apparently a memory violation?

#include <iostream>
using namespace std;

int main(){
    int ok;
    int counter;
    do {
        int size;
        while (true) {
            cout << "Enter the number of perfect odd squares you want" << endl;
            cin >> size;
            if(size<1) {
                cout << "Enter a valid number" << endl;
                continue;
            }
            else break;
        }
        if (size%2==0) counter=size*2-1;
        else counter=size*2;
        int *A = new int[size];
        for (int i=1; i<=counter; i=i+2){
            A[i]=i*i;
            cout<<A[i] << endl;
        }
        delete[]A;

        cout << " Continue (1) or quit (0)?" << endl;
        cin >> ok;

    }while(ok==1);

}

Source: Windows Questions C++

LEAVE A COMMENT