I think that *something
and * something
are different.
What does the additional white space do?
occurs here -> void * malloc( size_t number_bytes );
I think that *something
and * something
are different.
What does the additional white space do?
occurs here -> void * malloc( size_t number_bytes );
int* foo == int *foo == int * foo == int * foo
The whitespace does not make any difference to the compiler.
When you use an asterisk to get the value of an address it is called the dereference operator. For example:
int x = *something;
In the example in your question the asterisk has a different meaning because it is part of a type, not part of an expression. It is used to specify that the return type is a pointer (in your specific example, a void pointer).
The extra space does not mean anything and is ignored by the compiler. It is there only to aid readability.
The *
operator in a declaration always binds to the declarator; the line
void * malloc (size_t number_bytes);
is parsed as though it had been written
void (*malloc(size_t number_bytes));
It's an accident of C syntax that you can write T *p;
or T* p;
or even
T * p;
but all of them are parsed as T (*p);
-- the whitespace makes no difference in how the declarations are interpreted.
C ignores extraneous whitespace, so "* "
should have the same effect as "*"
.
If you want more clarification, please post a code example.
Check out this article on Pointers
Those two lines do the exact same thing.
In your void * malloc(...)
example, void *
is the type. malloc
returns a pointer to void, which is just a pointer that needs to be cast to a particular type in order to be useful.