Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Included are some snippets of the code I am using that I am having null pointer

ID: 2246824 • Letter: I

Question

Included are some snippets of the code I am using that I am having null pointer issues with (which I assume are seg fault errors but I am using VS for the first time so unsure). How am I supposed to be using such an array?

Exception thrown at 0x00007FF680A22F90 in hw1.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Unhandled exception thrown: read access violation.
this->**entries** was nullptr.

Mat2By2::Mat2By2(BigInt e11, BigInt e12, BigInt e21, BigInt e22) {
entries[0][0] = e11;
entries[0][1] = e12;
entries[1][0] = e21;
entries[1][1] = e22;

}

class Mat2By2
{
private:
    /**
     * A pointer to an array containing the entries for this matrix
     */
    BigInt** entries;

Explanation / Answer

PROGRAM CODE:

class Mat2By2

{

private:

/**

* A pointer to an array containing the entries for this matrix

*/

BigInt** entries;

public:

Mat2By2(BigInt e11, BigInt e12, BigInt e21, BigInt e22) {
// initialize the array for number of rows

entries = new BigInt*[2];

// initialize each row for number of colums

entries[0] = new BigInt[2];

entries[0][0] = e11;

entries[0][1] = e12;

entries[1] = new BigInt[2];

entries[1][0] = e21;

entries[1][1] = e22;

}

};