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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:55:33+00:00 2026-05-25T14:55:33+00:00

Possible Duplicate: How do I use arrays in C++? To put it simply, is

  • 0

Possible Duplicate:
How do I use arrays in C++?

To put it simply, is a multidimensional array in C++ an array of arrays or is it simply a single array which behaves like it’s multidimensional?

A friend of mine explained that arrays in C++ are simply constant pointers, and that multidimensional arrays are also constant pointers whose elements are addressed by more than one index (i.e. they are pointers pointing to one big array, and the offset of the elements are calculated using multiple indices).

I believe that multidimensional arrays are single dimensional arrays of pointers which point to other arrays because when passing multidimensional arrays as function arguments I often use the syntax:

void copy_matrix(int ** matrix);

If not, is it possible to create an array of arrays in C++ and assign the value of each sub-array at compile time – equivalent to the semantics of the following statements:

int line[2][2];

line[0] = {100, 100};
line[1] = {200, 200};

The above statements generate a compile time error. A quick (untested) hack I came up with was:

int line[2][2];

void assign(int index, int * point, int length) {
    for (int i = 0; i < length; i++) {
        line[index][i] = point[i];
    }
}

assign(0, {100, 100}, 2);
assign(1, {200, 200}, 2);

However, I believe that there must be a more elegant way to achieve the same result. I hope to clearly understand these concepts, and any input is appreciated.

  • 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-25T14:55:34+00:00Added an answer on May 25, 2026 at 2:55 pm

    The brace-list initializer only works during initialization, and it cannot be used for assignment, as you seem to attempt.

    Instead, just initialize the multi-dimensional array all at once:

    int line[2][2] = { {100, 100}, {200, 200} };
    

    In response to your first sentence: Arrays are arrays and pointers are pointers, and they’re not the same thing. An array does however decay to a pointer to the first element with ease, and x[n] is equivalent to *(x + n). This applies recursively to multi-dimensional arrays as well.

    Arrays T[N] are contiguous in memory for T and sizeof(T[N]) == N * sizeof(T); therefore, arrays of arrays T[N][M] are contiguous both for T[N] and for T.

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

Sidebar

Related Questions

Possible Duplicate: Array versus List<T>: When to use which? Is there any best practice
We can use array_unique() for remove duplicate entry from a single multidimensional array in
Possible Duplicate: Escape string for use in Javascript regex I have a msg like
Possible Duplicate: When should you use 'friend' in C++? I was brushing up on
Possible Duplicate: How do I use arrays in C++? I am not sure if
Possible Duplicate: Dynamic array in Stack? How do compilers treat variable length arrays Someone
Possible Duplicate: Why use iterators instead of array indices? string::iterator it; for (it =
Possible Duplicate: MySQL query using an array How to use an array of values
Possible Duplicate: String concatenation vs array implode in PHP there are situations in which
Possible Duplicate: PHP Sort a multidimensional array by element containing date I have some

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.