Posted:

**Mon May 23, 2005 2:22 am**ok i know this topic has been on these forums, but can somebody pls explain to me how does the pointer arimethic in PocketC language file work? i'm really struggling to learn how to work stuff in pocketC, and the forum threads are all beyond me =P i tried the following code

int array[100];

pointer twod[10]; // after init(), this can be treated

// like at 10x10 matrix

init() {

int i;

for (i=0;i<10;i++)

twod[i]=array + i*10; // Pointer arithmetic

}

main() {

int x, y;

init();

for (x=0;x<10;x++)

for (y=0;y<10;y++)

twod[x][y]=x * y; // Sets array[x*10 + y] = x*y

}

but it just gave me a Virtual Machine Error

addr: 83, Func:init, Global ref out of range

then i tried this method by FrankG

int xtable[100]; // but I want 25x4

int ix(int row, int col) {return row*25+col;}

for (row=0;row<25;row++)

for (col=0;col<25;col++)

xtable[ix(row,col)] = 0;

tho i couldn't get it to work

any help would be appreciated, thanks !

int array[100];

pointer twod[10]; // after init(), this can be treated

// like at 10x10 matrix

init() {

int i;

for (i=0;i<10;i++)

twod[i]=array + i*10; // Pointer arithmetic

}

main() {

int x, y;

init();

for (x=0;x<10;x++)

for (y=0;y<10;y++)

twod[x][y]=x * y; // Sets array[x*10 + y] = x*y

}

but it just gave me a Virtual Machine Error

addr: 83, Func:init, Global ref out of range

then i tried this method by FrankG

int xtable[100]; // but I want 25x4

int ix(int row, int col) {return row*25+col;}

for (row=0;row<25;row++)

for (col=0;col<25;col++)

xtable[ix(row,col)] = 0;

tho i couldn't get it to work

any help would be appreciated, thanks !