Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rutgers!cunixf.cc.columbia.edu!cubmol!ping From: ping@cubmol.bio.columbia.edu (Shiping Zhang) Newsgroups: comp.lang.c Subject: Re: sizeof and multi-dimensional arrays Message-ID: <1991Jan6.023116.5690@cubmol.bio.columbia.edu> Date: 6 Jan 91 02:31:16 GMT References: <1991Jan5.050613.22303@Neon.Stanford.EDU> <4596@sactoh0.SAC.CA.US> Reply-To: ping@cubmol.bio.columbia.edu (Shiping Zhang) Organization: Dept. of Biology, Columbia Univ., New York, NY Lines: 24 In article <4596@sactoh0.SAC.CA.US> jak@sactoh0.SAC.CA.US (Jay A. Konigsberg) writes: >Also I bumped the array to "char x[5][6]" and got: >sizeof(x[0])=6 >sizeof(*x)=6 >sizeof(x)=30 >This seems to be one of the finer differences between pointers and arrays. ... >sizeof(x[0]) makes sense as it returns the total size of that dimmension > of the array. > >sizeof(*x) DOES NOT make sense. The size of a pointer on this machine > is 4 bytes. (Note: adding "char *y; sizeof(y) does return 4). For an array x, *x is equivalent to x[0], so sizeof(x[0]) and sizeof(*x) should get the same number. Don't be confused with the difference between *x and &x. *x means a point in a declaration, but not in an expression. -ping