Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!lethe!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Subject: Re: Using sizeof() on a parameter array Message-ID: <1991May19.120332.8872@druid.uucp> Organization: D'Arcy Cain Consulting, West Hill, Ontario References: <12151@jarthur.Claremont.EDU> Date: Sun, 19 May 91 12:03:32 GMT In article <12151@jarthur.Claremont.EDU> Jim Seidman writes: >void test(char param[80]) { > char local[80]; > > printf("sizeof(param) = %d\n", sizeof(param)); > printf("sizeof(local) = %d\n", sizeof(local)); >} >Now, I thought that this should print out the same size for both, namely >80. But according to MSC, local has a size of 80, and param has a size >of 2 (the size of a pointer). The assumption that you seem to be making here is that the parameter param is the entire array. Arrays are not passed in C but rather a pointer to the initial element of the array. The compiler treats the above as: void test(char *param) and if you read it that way the above makes perfect sense. -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government Toronto, Ontario, Canada | like no government! +1 416 424 2871 |