Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3757180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:58:00+00:00 2026-05-19T09:58:00+00:00

Here we are once again good people of the internet. This is the code

  • 0

Here we are once again good people of the internet.

This is the code I’m using:

//This is what is in the header file
int *myArr[]; // A two-dimensional array representing holding the matrix data

//This is what is in the definition file
Matrix::Matrix(int n, int m)
{
    myRows = n;
    myColumns = m;
    initialize();
}

void Matrix::initialize()
{
    *myArr = new int[myRows];

    for (int i=0; i < 3; i++)//Only set to 3 since myRows is acting crazy
    {
        myArr[i] = new int[myColumns];
    }
}

For some reason when I use myRows variable to create the myArr array it just seems to stop referencing the value it was pointing towards before.

For instance I give it the value 3 and after the *myArr = new int[myRows] has been executed it changes the value of myRows to 9834496, which I don’t understand.

Does the “new” de-reference the variable or something?
Or am I doing something wrong?

Oh and since this is a school practice project (so I won’t blame you if you don’t answer) I would prefer an answer over working code, so that I could know what I did wrong for future projects.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:58:00+00:00Added an answer on May 19, 2026 at 9:58 am
    int *myArr[];
    

    This is wrong! You’ve to tell the compiler the size also, of your array of pointer. How about if you declare int a[]. You’re telling the compiler to create an array of int, of unknown size, which is not allowed in C++. That is why you cannot do that.

    I would suggest you to do this:

    int **myArr;
    
    void Matrix::initialize()
    {
        myArr = new int*[myRows]; //note int* here!
    
        for (int i=0; i < myRows; i++)
        {
            myArr[i] = new int[myColumns];
        }
    }
    

    This should work now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once again I found JavaScript code on the Internet that contains an inline function
Here I use two images. when i click once on the Sort_down.png image then
Hello pros I come here once again for help with php programming. I am
Once again I'm asking this question, and still can't find any reasonable solution. I
I was looking for good code for searching index using lucene.net. i got one
Once again a very beginner-ish question, but here I go: I would like to
Sorry to ask this kind of question once again but I could not solve
Here's an example: http://jsfiddle.net/7g8GD/1/ Once you have entered an invalid input and hit enter
Here's my Zend code: <?php require_once ('Zend\Form.php'); class Sergio_Form_registrationform extends Zend_Form { public function
Here i got a problem in my script, Once we set one radio button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.