# Thread: multidmensional dynamic array

1. I need that twodimensional bool array to write in all possible combinations of 0 and 1 without repeating.

So if I have a variable x = 3 (which means number of cells)

There are 3^2 (8) possible combinations.

Now the array should look like:

Code:
```0: 0 0 0
1: 0 0 1
2: 0 1 0
3: 0 1 1
4: 1 0 0
5: 1 0 1
6: 1 1 0
7: 1 1 1```
Any help on implementing this would be highly appreciated!

2. If I were given so many arbitrary restrictions like you have in your assignment. I would write my own custom container class. But I guess I am full of crazy ideas like that---or perhaps I understand that the whole objective of the assignment is to get you to realize that is the best option.

3. I'm probably being stupid, but why do you need a 2D array for this?

I also think that tabstop has given the answer. Use bool (*table)[2] = new bool [somenumber][2]

Or just use a fixed size array if you can be reasonably sure that x isn't going to be enormous - there is no great difference in how much memory you can allocate for a dynamic array or a fixed array, and until you actually USE the mmemoy in a fixed array, it won't actually use up (much) RAM in your machine.

--
Mats

4. Originally Posted by l2u
I need that twodimensional bool array to write in all possible combinations of 0 and 1 without repeating.

So if I have a variable x = 3 (which means number of cells)

There are 3^2 (8) possible combinations.

Now the array should look like:

Code:
```0: 0 0 0
1: 0 0 1
2: 0 1 0
3: 0 1 1
4: 1 0 0
5: 1 0 1
6: 1 1 0
7: 1 1 1```
Any help on implementing this would be highly appreciated!
This is not a two-dimensional array with exactly two columns. This is a two-dimensional array where the columns (n) and rows (2**n) are both dynamic. Is it a requirement to use a two-dimensional array to solve this problem? It's pretty easy to get from 7 to 1 1 1 without it.

5. I also think that tabstop has given the answer. Use bool (*table)[2] = new bool [somenumber][2]
You can make this prettier with a well-placed typedef.
Code:
```typedef bool (*TwoBools)[2];
TwoBools *table = new TwoBools[somenumber]```

Popular pages Recent additions