|
From: Ramana K. <ra...@my...> - 2002-07-31 11:19:08
|
thanks ioannis, i have briefly read your reply and it is what i had feared.
is there any way to implement what i had before so that the sizeof operator
reports the size as if it were a local array? for example, can i pass the
array to the function by reference or dereference the pointer that is
passed?
-----Original Message-----
From: Ioannis Vranos [mailto:no...@ho...]
Sent: Wednesday, 31 July 2002 9:15 PM
To: 'Ramana Kumar'
Subject: RE: [Dev-C++] sizeof array
sizeof() reports the total size of the array when it is used in the
scope of its definition.
When you use an array as an argument of a function in reality it is not
an array but a pointer.
consider the following example:
void makea(char array[100])
{
while(*array)
*array++='a';
}
int main()
{
char somearray[500];
for(unsigned long i=0; i<sizeof(somearray)-2; i++)
somearray[i]='s';
somearray[sizeof(somearray)-1]='\0';
makea(somearray);
}
void makea(char array[100]) is equivallent to void makea(char *array)
and void makea(char array[])
So sizeof(array) when applied inside the makea() is equivallent to
sizeof(char *).
array there is char *array.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|