Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!uhccux!cs211s14 From: cs211s14@uhccux.uhcc.hawaii.edu (Julian Cowley) Newsgroups: comp.lang.c Subject: Pointer/array compatibility Message-ID: <4959@uhccux.uhcc.hawaii.edu> Date: 28 Sep 89 22:05:08 GMT Distribution: na Organization: University of Hawaii at Manoa Lines: 35 I have some basic questions regarding arrays and pointers: int a[2][3][5], ***ippp, **ipp, *ip, i, j; i = a[0][0][0]; /* ok */ ip = &a[0][0][0]; /* ok */ ip = a[0][0]; /* why? */ ipp = a[0]; /* why? */ ippp = a; /* why? */ i = ipp[i][j]; /* why^2? */ Why are the latter expressions legal? For instance, I thought that a[0][0] is interpreted as pointer to array 5 of int and ip as a pointer to int, so they would be incompatible. It becomes especially confusing with the next expression: a[0] is a pointer to an array 3 of array 5 of int, not a pointer to pointer to int. Also, ipp[i][j], as indicated in K&R, becomes *(*(ipp + i) + j). How does the compiler know what size to multiply i by? It would seem to me that by the rules of pointer arithmetic, i would be multiplied by the size of a pointer to int and would give incorrect results. Basically what I'm asking here is how the compiler decides that two pointer expressions are of the same type and how it goes about deciding the size of a pointed-to object. Thanks for your help. Julian Cowley cs211s14@uhccux.uhcc.hawaii.edu cs211s14@uhccux.bitnet