What is the function of an asterisk before a function name?
Solution 1
The asterisk belongs to the return type, and not to the function name, i.e.:
void* func_name(void *param) { . . . . . }
It means that the function returns a void pointer.
Solution 2
The * refers to the return type of the function, which is void *
.
When you declare a pointer variable, it is the same thing to put the *
close to the variable name or the variable type:
int *a;
int* a;
I personally consider the first choice more clear because if you want to define multiple pointers using the ,
separator, you will have to repeat the *
each time:
int *a, *b;
Using the "close to type syntax" can be misleading in this case, because if you write:
int* a, b;
You are declaring a pointer to int (a
) and an int (b
).
So, you'll find that syntax in function return types too!
Solution 3
The *
belongs to the return type. This function returns void *
, a pointer to some memory location of unspecified type.
A pointer is a variable type by itself that has the address of some memory location as its value. The different pointer types in C represent the different types that you expect to reside at the memory location the pointer variable refers to. So a int *
is expected to refer to a location that can be interpreted as a int
. But a void *
is a pointer type that refers to a memory location of unspecified type. You will have to cast such a void pointer to be able to access the data at the memory location it refers to.
Solution 4
It means that the function returns a void*
.

Comments
-
Aldee 6 months
I've been confused with what I see on most C programs that has unfamiliar function declaration for me.
void *func_name(void *param){ ... }
What does
*
imply for the function? My understanding about (*
) in a variable type is that it creates a pointer to another variable thus it can be able to track what address at which the latter variable is stored in the memory. But in this case of a function, I don't know what this*
asterisk implies. -
Aldee almost 11 yearsthanks for the answers guys but what does a void pointer mean?
-
Daniel Kamil Kozar almost 11 yearsIt's just an address to a location in memory. You don't know what it points to - it's up to you to cast the pointer to a proper type that you can later use. Of course, casting it to an invalid type (for example, let's say that void* points to a float, but you cast it to a char) will produce undefined results.
-
NPE almost 11 years@AldeeMativo: Also, see stackoverflow.com/questions/692564/…
-
Lundin almost 11 years"if you want to define multiple pointers using the , operator". This is considered poor programming style since it leads to bugs when combining pointers and variables of the same type. The solution isn't to obfuscate the way you declare pointers, the solution is to declare every variable on a line of its own. There does not exist any case where it makes sense to declare several variables on the same row. What are you trying to achieve by doing so, save keyboard presses? Clearly, wear and tear of the keyboard is a more serious matter than readability of the code...
-
Vincenzo Pii almost 11 yearsI never said I do that. I said that is a reason to prefer the "close-to-variable-name" syntax, because it never creates confusion. And I said that is a possible explanation for the same syntax used in function interfaces.
-
Dan almost 11 years
if you want to define multiple pointers using the , operator, you will have to repeat the * each time: int *a, *b;
In that context, the comma is a separator, not an operator. -
Jens over 8 years@DanielKamilKozar In C we don't cast pointers-to-void. We simply assign them. That's how it is standardized to work. (Unlike C++, which is a totally different beast.)
-
Daniel Kamil Kozar over 8 years@Jens : true, of course. Thanks for pointing this out. Thankfully, my knowledge has improved since then. :)
-
SOFe over 6 yearsBut why for function declarations?
-
Vincenzo Pii over 6 years@PEMapModder, that's just the return type of the function, in this case a pointer to
void
. -
SOFe over 6 years@VincenzoPii I understand that placing the deref operator closer to the var name can avoid confusion in var declaration lists, but I don't understand why this is also true for functions. You don't have one return type declaration for multiple function declarations anyway.
-
Vincenzo Pii over 6 years@PEMapModder I'd say that would be a consistency choice based on the convention that one would follow for variables to avoid confusions there. In other words, chose where to put the
*
because of variable lists (whatever uninfluential this use case may be) and stick to that for other cases :). -
SOFe over 6 yearsI see. Somehow it only feels more confusing...
int *operator*(int i){...}
... Doesn't that make code less readable? -
RoG over 4 years@Lundin I agree with you, and I do not do this myself, but I think people do it for the sake of compactness, which is related to readability. Out of interest, do you have a problem with doing it for declaring non-pointers?
short a, b, c;
etc.? -
Lundin over 4 years@RoG Yes, that is poor style as well, because it doesn't need much to fall apart into an unreadable mess.
short a=VERBOSE_CONSTANT,b=something?this:that,c=call_some_function();
. Now sneak some*
in there and you have a candidate for the IOCCC. -
skytree over 4 yearsHow about this one
Status (*fn)(shape_inference::InferenceContext*)
from link ? It uses parenthesis to group * with function name together. -
ywu over 1 yearI second @SOFe here. This post gives a good point but the example does not address the specific question thus causes confusion.