0
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];
    Insert(Array,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.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Hentairino
  • 111
  • 7
  • 3
    Closed as a dupe of the canonical. You forgot to loop through the `n` pointers you created and assign them a `new` address as well. – NathanOliver Feb 20 '20 at 13:54
  • 4
    using a `std::vector>` instead will save you from lots of pain – 463035818_is_not_an_ai Feb 20 '20 at 14:03
  • 1
    `0xCDCDCDCD` means uninitialized heap memory: [https://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations](https://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations) – drescherjm Feb 20 '20 at 14:21

0 Answers0