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 7609637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:13:13+00:00 2026-05-31T01:13:13+00:00

I am working with a 2D array in a VS2010 console application. I am

  • 0

I am working with a 2D array in a VS2010 console application. I am allocating the array as such:

Thing::Thing(int _n, bool _control){
    m = _n;
    control = _control;
    thisArray = new int*[m];
    for(int ii = 0; ii < m; ii++){
        thisArray[ii] = new int[m];
        for (int jj = 0; jj < m; jj++){
            thisArray[ii][jj] = 0;
        }
    }
    if (control == true){
        int num = 1;
        for (int jj = 0; jj < m; jj++){
            for ( int ii = 0; ii<m; ii++){
                if ((jj == (m-1)) && (ii == (m-1))){
                    std::cout << "inserting " << 0 <<
                        "at[" << ii << "][" << jj << "]" << std::endl;
                    thisArray[ii][jj] = 0;
                    std::cout << thisArray[ii][jj] << std::endl;
                } else{
                    std::cout << "inserting " << num <<
                        "at[" << ii << "][" << jj << "]" << std::endl;
                    thisArray[ii][jj] = num++;
                    std::cout << thisArray[ii][jj] << std::endl;
                }
            }
        }
        pi.x = m-1;
        pi.y = m-1;
    }
}

then I attempt to display it through

void Thing::display(){
    int x = 0;
    int y = 0;
    for( ; y < m; y++){
        for( x = 0; x < m; x++){
            if (Point(x, y) == pi){
                std::cout << "[  ]";
            }
            std::cout << "[" << thisArray[x][y] << "]";
            if ( x == m ){
                std::cout << std::endl;
            }
        }
    }
}

but it seems like it is only displaying the first dimension as output when I pass in 4, and true looks like this:

inserting 1 at[0][0]1
inserting 2 at[1][0]2
inserting 3 at[2][0]3
inserting 4 at[3][0]4
inserting 5 at[0][1]5
inserting 6 at[1][1]6
inserting 7 at[2][1]7
inserting 8 at[3][1]8
inserting 9 at[0][2]9
inserting 10 at[1][2]10
inserting 11 at[2][2]11
inserting 12 at[3][2]12
inserting 13 at[0][3]13
inserting 14 at[1][3]14
inserting 15 at[2][3]15
inserting 0 at[3][3] 0
[1][2][3][4]

, and when I add the array to my watch list the system shows the pointer to pointer to a single value, and then will only show me the first element, and not all of the elements.

it throws no run time access errors, or anything like that, but when I try to display the array it only does the first row. Note: I have been asked to use an actual 2D-array of ints, and am not allowed to use a pre-written library, or a single dimensional lie.

edit: added additional output info.
edit2 (resolved): in display changed the second for loop to be

for (x = 0; x < m; x++)

when holding values external to a for loop insure that they are reset for circular iteration.

  • 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-31T01:13:15+00:00Added an answer on May 31, 2026 at 1:13 am

    In your display function, you have to reset x at each iteration of the outer y loop.
    It would even be clearer, if you did the initialization within the for statement:

    for(int y = 0; ; y < m; y++){
        for(int x = 0; ; x < m; x++){
    

    And to view a pointer as an array in Visual C++ debugger, you can look at that other question.

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

Sidebar

Related Questions

I am working on a C# application that works with an array. It walks
I'm working with an array of JavaScript Objects as such: var IssuesArray = [{"ID"
If I am working with an associate array like such: Array ( [Username] =>
I am currently doing this but it isn't working: var tempArray=new Array(); var number
When working on my latest web application and needing to use the Array.forEach function,
I have been working with a string[] array in C# that gets returned from
I’m working on a multi dimensions array but i have a problem Imagine I
While working with ActiveRecord I have a table which stores a serialized array of
I'm working on a program that uses PHP's internal array pointers to iterate along
I'm working on a class that is storing a 2D array of class MyType

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.