Array pointers.

Pages: 12
your post:
[ s1 ] - > [ s2 ] -> [ s3 ] - > [ Array of int pointers pointing to ints, for 2d array ]
(numbers for clarity)

[Array of int pointers pointing to ints, for 2d array] → [int*] (each element of the array is pointer to array , so int*)
[s3] -> [int*] → int**] -> [int*] (s3 is a pointer to 2D array, so int**)
[s2] -> [int**] -> [int*] → [int***] -> [int**] -> [int*] 
[s1] -> [int***] -> [int**] -> [int*] → [int****] -> [int***] -> [int**] -> [int*] 
So yes, there is four level of indirection until you hit int, but 3 until you hit your outer array element
Last edited on
Lets use another trick:
1
2
3
4
5
6
7
8
9
10
using A = int*;
using B = int**;
using C = int***;

C * s = new C {};
*s = new B {};
**s = new A[3] {};
(**s)[0] = new int[12] {};
(**s)[1] = (**s) + 4;
(**s)[2] = (**s) + 8;

Now the s [s1] points to *s [s2], which points to **s [s3], which points to array of three pointers. Each pointer in the array points to a different element in a block of 12 integers, creating a virtual 3*4 table of integers.

The type aliases may (or may not) simplify how the code is read.
Okay! So, I just want to thank everybody for all the help, I have some code here, and I'm wandering if you have a moment you can take a quick peak, I have some ugly for loops to fix and couts to view whats going on but it seems to be working.

http://pastebin.com/aVEfibYk

I did have a question, all those functions I need to call need to be called from main, is it okay that I use the method that I used to call the first two, for all of them? Or is there a more efficient / prettier way? I also haven't set the table up completely.
Last edited on
Topic archived. No new replies allowed.
Pages: 12