It's a pointer to a pointer.
Actually, it is an array of an array.
For example, say you have an array of your classmate's ages:
Code: Select all
#define MYCLASS_BILL 0
#define MYCLASS_BOB 1
// int age[30];
int age[];
ArrayInit(age, 0, 30);
age[MYCLASS_BILL] = 14;
age[MYCLASS_BOB] = 15;
//Bob is one year older than Bill is. Ha, in your face, Bill!
And now you want to do all the classes in your school:
Code: Select all
#define MYCLASS 0
#define MR_KIM 1
#define MS_DODDS 2
#define DR_FALKEN 3
#define DR_YUNG 4
#define MASTER_YODA 5
#define DR_MOTTO 6
#define MR_SMILE 7
#define MR_GREGROVICH 8
#define MR_RIDER 9
// int age2[10][30];
int age2[][];
ArrayInit(age2, age, 10);
age2[MYCLASS][MYCLASS_BILL] = 14;
age2[DR_FALKEN][DAVID] = 16;
//Alternatively, you can do
int myclass[], mr_kim[], ms_dodds[], dr_falken[], dr_yung[], master_yoda[], dr_motto[], mr_smile[], mr_gregrovich[], mr_rider[];
ArrayInit(myclass, 14, 30);
myclass[MYCLASS_BOB] = 15;
ArrayInit(mr_kim, 14, 30);
ArrayInit(ms_dodds, 15, 30);
ArrayInit(dr_falken, 15, 30);
dr_falken[DAVID] = 16;
ArrayInit(dr_yung, 16, 30);
ArrayInit(master_yoda, 16, 30);
ArrayInit(dr_motto, 16, 30);
ArrayInit(mr_smile, 17, 30);
ArrayInit(mr_gregrovich, 17, 30);
ArrayInit(mr_rider, 17, 30);
ArrayBuild(age2, myclass, mr_kim, ms_dodds, dr_falken, dr_yung, master_yoda, dr_motto, mr_smile, mr_gregrovich, mr_rider);
For multiple schools, you can use 3D arrays:
Code: Select all
int myschool[][];
myschool = age2;
int waterloo_university[][];
int jedi_school[][];
//int age3[3][10][30];
int age3[][][];
ArrayBuild(age3, myschool, waterloo_university, jedi_school);
Alternatively, you could use a 1D-Array to simulate a 2D array like this:
Code: Select all
int ArrayAccess2Di(int &arr[], unsigned int pos_e1, unsigned int pos_e2, unsigned int size_e2)
{
return(arr[(pos_e1*size_e2)+pos_e2]);
}