Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!julius.cs.uiuc.edu!rpi!uupsi!sunic!news.funet.fi!hydra!kreeta!wirzeniu From: wirzeniu@cs.Helsinki.FI (Lars Wirzenius) Newsgroups: comp.lang.c Subject: Re: sizeof and multi-dimensional arrays Message-ID: <10303@hydra.Helsinki.FI> Date: 5 Jan 91 22:00:25 GMT References: <4596@sactoh0.SAC.CA.US> Sender: news@cs.Helsinki.FI Organization: University of Helsinki, Department of Computer Science Lines: 14 In article <4596@sactoh0.SAC.CA.US> jak@sactoh0.SAC.CA.US (Jay A. Konigsberg) writes: >[ char x[5][6]; sizeof(*x) gives 6 ] >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). But *x isn't a pointer, it's an array. First the the type of x decays from "array 5 of array 6 of char" into "pointer to array 6 of chars". (See for example: _Standard_C_, by P.J.Plauger and Jim Brodie, page 74, or K&R-2, Section A7.1, "Pointer Generation", page 200.) This pointer is dereferenced with '*', and the result is an array of type |char [6]|, which has the size 6. -- Lars Wirzenius wirzeniu@cs.helsinki.fi wirzenius@cc.helsinki.fi