# How to declare 2D array?

**URL:** <https://forum.kirupa.com/t/how-to-declare-2d-array/270004>\
**Category:** Uncategorized\
**Created:** [September 4, 2008, 4:01am UTC](https://forum.kirupa.com/t/how-to-declare-2d-array/270004 "2008-09-04T04:01:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [September 4, 2008, 4:01am UTC](https://forum.kirupa.com/t/how-to-declare-2d-array/270004/1 "2008-09-04T04:01:37Z")

</div>

I have two questions about arrays.

**1)** I created an array with [][] and passed it into a function expecting \*\*. I got an error saying: \*cannot convert parameter 1 from ‘gfx::Vec3f [800][600]’ to 'gfx::Vec3f \*\*\*. I thought [][] and \*\* are the same thing!

**2)** I tried doing “Vec3f image[width][height];” before, but the compiler complained saying _“expected constant expression”_. So I changed it to “Vec3f image[800][600];” to make it compile. Why must I do this hardcoding?

```auto

Pixels::Pixels(Vec3f** colors, int width, int height)
{
	this->width = width;
	this->height = height;
	this->image = colors;
}

```

```auto

int width = 800;
int height = 600;

Vec3f image[800][600];

for(int w = 0; w < width; w++)
	for(int h = 0; h < height; h++)
		image[w][h] = Vec3f(w / width, h / height, w / height); 

Pixels pixels = new Pixels(image, width, height);

```
