JS wrote:
"Victor Bazarov" <v.********@comAcast.net> skrev i en meddelelse
news:mx*******************@newsread1.mlpsca01.us.t o.verio.net... JS wrote: If I have a function that looks like this:
char *alloc(int n)
{
....
return allocp - n;
}
I guess the "*" in the first line of the function belongs to "char" and not the name of the function. "char *"....not "*alloc". Right?
Right. An asterisk cannot be part of a name. It says that the function
'alloc' returns a pointer to char.
V
Just a bit misleading because of the missing blank followed by the "*".
Would seem a bit more clear if one wrote:
char * alloc(int n)
It is the same as
2+3
you can write it any way you want
2+ 3
2 +3
2 + 3
it always means the same thing: the addition of 2 and 3
There is a possible pitfall with that pointer-'*' however:
Actually the situation is this:
The '*' belongs more to the thing on its right then to the thing
on its left. In case of function return types this makes no difference.
But consider:
int* i, j;
What does this define?
Well. It defines a pointer variable named 'i' and (surprise) it defines
an int variable named 'j'. Note: 'j' is an int (!) not a pointer to int (!).
That's why most C programmers prefer to write
int *i, j;
to make this clear without any doubt.
In C++ much less pointers are used, and most programmers agree, that there
should be only one variable defined in each definition, thus a C++ programmer
would write:
int *i;
int j;
and now the whitespace can easily be moved to the data type without fooling
anybody:
int* i;
int j;
--
Karl Heinz Buchegger
kb******@gascad.at