Pointer to an array of pointers

Hey guys, I'm just trying to get a handle on the uses of pointers here. Though clearly from my errors I'm missing a key concept :-)

Here is my code: (You can assume that the array, "array_size" has values in it, I did this part in another function)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int main()
{ bool **ptr_array;
  int num;
  int *array_size;
  cin>>num;

  ptr_array = new bool*[num];
  array_size = new int[num];
  Setup(ptr_array, array_size, num);

  return 0;
}

void Setup(bool *ptr_array[], int array_size[], int num)
{ int i;

  for (i=0; i<num; i++)
     Initialize(ptr_array[i], array_size[i]);
}

void Initialize(bool word[], int num)
{ int i;

  for (i=0; i<num; i++)
     word[i] = false;
}

Once the program reaches the word[num] = false; some unhandled exceptions pop up. Any clarification you guys can give me on these techniques will be greatly appreciated!

edit - My mistake, I simplified my code a bit from my actual program and mixed up the loops, now the code should be in its correct form.
Last edited on
uhh...why are you looping without using its iterator?

the 'i' have no any reference at all in your code.
Good catch!

Haha I wish that was my error though, that was merely an error in summarizing my code over from the main base.

So my original unhandled exceptions persist everyone!
Your bool array only contains uninitialized pointers.
You need to allocate memory for each ptr_array[i].
That was it, thanks a ton!
Topic archived. No new replies allowed.