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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:22:58+00:00 2026-05-23T14:22:58+00:00

all. I have an interesting question, posed to me by my C++ professor. It

  • 0

all. I have an interesting question, posed to me by my C++ professor. It is also used in some programming job interviews, apparently.

Here’s the situation. I have a two-dimensional array (matrix) of int’s:

int array1[][2] = {{11, 12}, {21, 22}};

I would like to create a second two-dimensional array, array2, that points to this first array. That is, they would occupy the same space in memory.

The obvious solution is to use pointers. So, I declared array2 like so:

int (*array2)[2][2];
array2 = &array1;

This seems to work. Now, here’s the catch. I am trying to subtract 11 from array1, but do it by referencing array2. Here is the code for what I’m trying to accomplish:

for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
        // Trying to do the equivalent of this:
        array1[i][j] -= 11;
    }
}

I have tried the following in the body of the internal for-loop, all without success:

// Second row not affected
*(array2[i][j]) -= 11;

// Second row not affected
*(*(array2[i]) + j) -= 11;

// incompatible types in assignment of `int' to `int[2]'
*( *(array2 + i) + j) -= 11;

Any ideas? I suspect there’s something simple that I’m just not getting here.

Thanks!

  • 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-23T14:22:59+00:00Added an answer on May 23, 2026 at 2:22 pm

    Since this is C++, you can create an alias array using a reference, that’s exactly what they do.

    int array1[][2] = {{11, 12}, {21, 22}};
    int (&array2)[2][2] = array1;
    
    for(int i=0; i<2; ++i)
        for(int j=0; j<2; ++j)
             array2[i][j] -= 11;
    

    Although the problem is more likely a C problem with the expectation that array2 would be a pointer to the first row of array1

    int array1[][2] = {{11, 12}, {21, 22}};
    int (*array2)[2] = array1;
    
    for(int i=0; i<2; ++i)
        for(int j=0; j<2; ++j)
             array2[i][j] -= 11;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some interesting problem for an hour.. In my flex project, all width
Here's an interesting question about the various quirks of the C++ language. I have
hi to all i have an interesting question is it possible to copy onclick
I have a interesting question for you all. My client wants a way to
So I have been running into all kinds of interesting problems in VisualStudio 2008
I have a window with 3 radiobuttons like this(removed all non interesting props): <Control
I have a situation where all my selectors all have the same ancestor element
I was posed an interesting question from a colleague for an operational pain point
Here's an interesting question - when should you force automatic updates? I was thinking
I think you programmers must have some interesting naming convention of variables. I have

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.