Jump to content
  • Advertisement
Sign in to follow this  
xidis

multidimensional array types

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Given this code:
int main()
{
    int array[3][4][6];
    
    return 0;

}

What is the type of array. I believe it is a pointer to the first element which is an array of int arrays. How would you represent that in code?

Share this post


Link to post
Share on other sites
Advertisement
No, the type of the array is int [3][4][6]; It however has an implicit decay to the int (*)[4][6] type. So you could in theory do something like:

int (*parray)[4][6] = array;


However, such a usage is error prone. I would recommend wrapping the array in a struct or class and pass pointers or references to that instead.

Share this post


Link to post
Share on other sites
Quote:
Original post by xidis
Given this code:

*** Source Snippet Removed ***

What is the type of array.


Well the type is exactly that a 3d array of ints, unless you mean how is it representated

Quote:
Original post by xidis
I believe it is a pointer to the first element which is an array of int arrays.


well in C++ given T foo[m][n][o]

The type of T[j][k] is of const T& or T& depending on the context.

The type of T[j] is of const T (&)[o] or T (&)[o] depending on the context.

The type of T is of const T (&)[n][o] or T (&)[n][o] depending on the context.

if you not sure what the last two are, they are a reference to a (multidimensional) array.

Quote:
Original post by xidis
How would you represent that in code?


What do you mean?

Share this post


Link to post
Share on other sites
The type of the array is int [3][4][6].

The corresponding pointer type would be int (*)[4][6].

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
The corresponding pointer type would be int (*)[4][6].


const int (&)[4][6] or int (&)[4][6] for C++ [grin], although you do get abit more flexibility using pointers to arrays.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!