I know how to work pointers with a unidimensional array,(the identifier of the array points to its first element)..., but i would like to know how can i work the same with pointers but using arrays with more than one dimension?
Asked
Active
Viewed 488 times
0
-
5You will need to give an example of what you want to do (there are lots of different ways to use pointers and multidimensional arrays). Also, try reading some of the "Related" questions in the list on the right -->. – Oliver Charlesworth Sep 20 '11 at 13:26
-
knowing what language you want to do it in will also help – totallyNotLizards Sep 20 '11 at 13:27
-
1@jammy: The question is tagged "C". – Oliver Charlesworth Sep 20 '11 at 13:28
-
Read here: http://stackoverflow.com/questions/4810664/how-do-i-use-arrays-in-c – Shahbaz Sep 20 '11 at 13:28
-
@Oli - just saw that after i refreshed the page, oddly there werent any tag icons on the post while i was typing my answer :/ – totallyNotLizards Sep 20 '11 at 13:32
-
Read section 6 of the [comp.lang.c FAQ](http://c-faq.com). – Keith Thompson Sep 20 '11 at 15:07
1 Answers
1
The same:
int a[10]; // array(10) of ints
int* pa = a; // pa points to first int
pa++; // pa points to second int
int b[10][20]; // array(10) of arrays(20) of ints
int (*pb)[20] = b; // pb points to first array(20) of ints
pb++; // pb points to second array(20) of ints
If you want to traverse 2-dimensionally, use manual indexing:
int tab[W][H];
int* p = &tab[x+y*W]; // element (x,y)
p += 1; // one element forward (x+1)
p += W; // one column forward (y+1)

Kos
- 70,399
- 25
- 169
- 233