What is the asterisk function before the function name?

I was confused by what I see in most C programs that have an unfamiliar function declaration for me.

void *func_name(void *param){ ... } 

What does * mean for a function? My understanding of ( * ) in a variable type is that it creates a pointer to another variable, so it can keep track of which address the last variable is stored in memory at. But in this case, the functions I do not know what this asterisk * implies.

+49
c function pointers
Jan 18 2018-12-18T00:
source share
4 answers

The asterisk refers to the type of the return value, and not to the name of the function, that is:

 void* func_name(void *param) { . . . . . } 

This means that the function returns a pointer to void.

+55
Jan 18 2018-12-18T00:
source share
— -

* refers to the type of function return, which is void * .

When you declare a pointer variable, it is the same as the * tag close to the variable name or variable type:

 int *a; int* a; 

I personally think the first choice is more understandable, because if you want to define several pointers using a separator, you have to repeat * 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 declare a pointer to int ( a ) and int ( b ).

So, you will also find this syntax in the returned functions!

+15
Jan 18 2018-12-18T00:
source share

* refers to the type of return. This function returns void * , a pointer to some location of memory of indefinite type.

A pointer is a type of variable in itself that takes the address of some memory location as its value. The different types of pointers in C represent the different types that you expect to be in the memory referenced by the pointer variable. Thus, it is expected that int * will refer to a location that can be interpreted as int . But void * is a pointer type that refers to a memory location of an unspecified type. You will need to indicate such a pointer to void in order to have access to the data in the memory cell to which it refers.

+9
Jan 18 2018-12-18T00:
source share

This means that the function returns void* .

+5
Jan 18 '12 at 13:52
source share



All Articles