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

  • Home
  • SEARCH
  • 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 9178035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:27:31+00:00 2026-06-17T17:27:31+00:00

I am a c++ newbie. While learning I came across this. if I have

  • 0

I am a c++ newbie. While learning I came across this.

if I have a pointer like this

int (*a)[2][3]

cdecl.org describe this as declare a as pointer to array 2 of array 3 of int:

When I try

int x[2][3];

a = &x;

this works.

My question is how I can initialize a when using with new() say something like

a = new int [] [];

I tried some combinations but doesn’t get it quite right.

Any help will be 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-06-17T17:27:33+00:00Added an answer on June 17, 2026 at 5:27 pm

    It’s probably not the answer you’re looking for, but what you
    need is a new expression whose return type is (*)[2][3] This
    is fairly simple to do; that’s the return type of new int
    [n][2][3]
    , for example. Do this, and a will point to the
    first element of an array of [2] of array of [3] int. A three
    dimensional array, in sum.

    The problem is that new doesn’t return a pointer to the top
    level array type; it returns a pointer to the first element of
    the array. So if you do new int[2][3], the expression
    allocates an array of 2 array of 3 int, but it returns
    a pointer to an array of 3 int (int (*a)[3]), because in C++,
    arrays are broken (for reasons of C compatibility). And there’s
    no way of forcing it to do otherwise. So if you want it to
    return a pointer to a two dimensional array, you have to
    allocate a three dimensional array. (The first dimension can be
    1, so new [1][2][3] would do the trick, and effectively only
    allocate a single [2][3].)

    A better solution might be to wrap the array in a struct:

    struct Array
    {
        int data[2][3];
    };
    

    You can then use new Array, and everything works as expected.
    Except that the syntax needed to access the array will be
    different.

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

Sidebar

Related Questions

Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Newbie here. I have this code: while (v < 360) { v +=10; RunIt();
This is a super newbie question, I've been programming for a while, but am
I'm a newbie to Asp.net,learning from the Apress's Begining Asp.net...book.While very curious to see
I am newbie to php, just starting learning it, while working with wordpress. I
I'm sort of newbie to programming & while making my way to learning, I'm
This is obviously newbie question so please bear with me. While trying to compile
I'm learning vba today, I'm a newbie and I have a few questions about
Newbie questions. While learning Objective-C using Xcode 4.5.3 and the book Programming In Objective-C
A newbie to JUnit (in fact JUnit 4) and came across suite way of

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.