Advertisement

pointer trouble

Started by January 05, 2000 11:55 AM
9 comments, last by fenrir 24 years, 11 months ago
Don''t know if it helps... but maybe this is what you''re looking for.

int b[2][2] = { 0, 0, 0, 0 };
int *pb = b[0];

Now I could do:

pb[0] = 1;
pb[1] = 2;
pb[2] = 3;
pb[3] = 4;

printf("b[0][0] = %i\nb[0][1] = %i\nb[1][0] = %i\nb[1][1] = %i", b[0][0], b[0][1], b[1][0], b[1][1]);

The output would be:

b[0][0] = 1
b[0][1] = 2
b[1][0] = 3
b[1][1] = 4

Is that what you''re trying to do? You could multiply the array indices to get the index to use with the pointer quite easily.

Good luck

Starfall

This topic is closed to new replies.

Advertisement