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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:11:53+00:00 2026-05-26T00:11:53+00:00

So I want to initialize an int 2d array very quickly, but I can’t

  • 0

So I want to initialize an int 2d array very quickly, but I can’t figure out how to do it. I’ve done a few searches and none of them say how to initialize a 2D array, except to do:

int [SOME_CONSTANT][ANOTHER_CONSTANT] = {{0}};

Basically, I’ve got 8 vertices, and I’m listing the 4 vertices of each face of a cube in an array. I’ve tried this:

int[6][4] sides = {{0, 1, 2, 3}, {4, 5, 6, 7}, {0, 4, 7, 3}, {7, 6, 2, 3}, {5, 1, 2, 6}, {0, 1, 5, 4}};

But that tells me that there’s an error with ‘sides’, and that it expected a semi-colon. Is there any way to initialize an array quickly like this?

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-26T00:11:53+00:00Added an answer on May 26, 2026 at 12:11 am

    You have the [][] on the wrong side. Try this:

    int sides[6][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}, {0, 4, 7, 3}, {7, 6, 2, 3}, {5, 1, 2, 6}, {0, 1, 5, 4}};
    

    Keep in mind that what you really have is:

    int **sides
    

    (A pointer to a pointer of ints). It’s sides that has the dimensions, not the int. Therefore, you could also do:

    int x, y[2], z[3][4], ...;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to initialize a 2d array.. but my code doesn`t work, can somebody
I need to initialize few objects, it can take a while so I want
Lets say I have an array like int arr[10][10]; Now i want to initialize
I want to initialize an array and then initialize a pointer to that array.
I want to initialize a global array of structure in a .cpp file. My
I want to initialize a vector like we do in case of an array.
I have the following code. Basically I want to initialize a std::array of non-POD
How do I initialize a pointer to a literal array? I want *grid to
I want to create an int array with 999 elements, each of which has
I want to initialize array of c-strings with zero pointers in MSVC2010 // Foo.h

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.