Point taken, si I made a simple mistake it should have been "an array name parameter is a pointer" K&R page 99 Bob Ammerman wrote: > Ok, > > I've put on my language lawyer hat because I really have to clear up a > misconception that is dogging this thread: > > NOTE: An array name is _not_ a pointer in C. > > An array name is an identifier for an area of memory (the array). > > It is just that in _most_ contexts you can treat the array name as a pointer > to the first element of the array. The terminology typically used is that it > 'decays' to the pointer. > > There are at least two places where treating the array name as a pointer > breaks down: > > 1) You cannot change this 'pointer' to point to anything else, ever. > For example, given: > > char buf[20]; > char buf2[10]; > > buf = buf2; // This is illegal. You are trying to change the array name buf > to point to something else (in this case to be equal to the pointer to which > 'buf2' decays). > > 2) When using the array name in a sizeof operation, you get the size of the > entire array, _not_ the size of a pointer to the elements. Thus, given: > > char buf[20]; > > sizeof(buf) will be 20. > > 2) [Optional for advanced language-law students] There is actually an > exception to the rules described in 1 and 2, above. When an array is > declared as argument to a function: > > void foo(char buf[20]) > { > } > > Then within the function 'foo', buf really _is_ treated as a pointer to > char. You can freely adjust it or assign things to it: > > char buf2[20]; > ++buf; > buf = buf2; > > And sizeof(buf) will return the size of the pointer, not the buffer! > > Bob Ammerman > RAm Systems > (contract development of high performance, high function, low-level > software) > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads