RE: [Dev-C++] Number of elements of a multidimensional
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-11-29 13:25:34
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Carlos Garc=EDa del Monte
> Sent: Thursday, November 28, 2002 6:54 PM
> To: dev-cpp-users-list
> Subject: Re: [Dev-C++] Number of elements of a multidimensional
>=20
>=20
> The sizeof applied to a array will give you the size of a=20
> pointer, never
> the size of the array.
> Say char *array; or char array[];
As a function argument, because only then the second is a pointer.
Inside the scope of its definition, a
char array[]=3D"12345678901234567890";
size_t x=3Dsizeof(array);
x will always be 21 (the '\0' included).
However in void f(char array[]);
is equivallent to void f(char *);
so you can do array++; for example because all tthese are ponters.
You can do that even in the case:
void f(char array[20])
{
/* The !=3D'\0' is not needed */
while(*array!=3D'\0')
*array++=3D'a';
}
All "array" arguments of functions are pointers but we can use the array
syntax for notational purposes.
> Then sizeof(array) =3D 4. (at least in my intelIII x86, with win2k 4 =
is
> the size for any kind of pointer).
>=20
> The only solution is to have some special value for the end of the
> array. Which for strings is '\0', and you can try to set another
> depending on which kind of data you're working with and which range of
> values you can find, so you can then choose on of the values which are
> out of the range to set as that special value. So you can reach for it
> and you can then now, with the approppriate functions you can=20
> write the
> total size of the array and the size of each row of the=20
> multidimensional
> array.
Yes he has to "remember" the size of the array when he passes it across
functions, even by passing the sizes as additional arguments, or other
tricks.
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|