On 2006-06-26, kd <> wrote:
> Newbie question here. It's been a while since I've done C programming,
> and I hit a wall last night.
>
> Let's say I have a three dimensional array, like so:
>
> int p[2][3][3] =
> {{{0,0,0},
> {1,1,1},
> {0,1,0}},
>
> {{0,1,0},
> {1,1,0},
> {0,1,0}}};
>
> I also have a number of other three dimensional arrays, generated with
> a code generating script. The size of each dimension varies with each
> one. Some are [5][3][3], some are [2][5][5], etc...
>
> How would I declare a variable that could hold any of these
> 3-dimensional arrays? I'm tripping over the pointer syntax.
>
> I'd like to be able to do something like:
> int ***val = p; //The variable p from the last example.
>
> I'm pretty sure that ***val is the wrong way to go about it.
>
No, ***p will do it. You'll be able to go through the array with p++,
(*p)++, and (**p)++, depending on which dimension you are moving
through. Indeed, it is pretty complicated.
Why are you doing this?
--
Andrew Poelstra <
http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
I know that area of town like the back of my head.