How to dynamically allocate 2D array and pass it into function

void Insert(float** Array, int n) {
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 6; j++)
            cin >> Array[i][j];

int main() {
    int n;
    cin >> n;
    float** Array = new float*[n];
    return 0;

Code above was my barebone attempt at passing and inserting values into dynamically allocated array, the code compiles and lets me input value n but inputing the very first number into the array results in this exception:

0xC0000005: Access violation writing location 0xCDCDCDCD.

I believe theres a problem with the way im inserting into the array but cant quite figure it out. Also Ive read about 0xCDCDCDCD and that im trying to write into non-existent memory or what not but cant figure it out, also the j value is supposed to be less than 6 for a reason.

asked on Stack Overflow Feb 20, 2020 by Hinterino Salterino • edited Feb 20, 2020 by NathanOliver

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0