for example:
struct entry *addentry (Struct entry *listPtr, int value){ }
why does the name have a *
I tried to understand but couldnt
for example:
struct entry *addentry (Struct entry *listPtr, int value){ }
why does the name have a *
I tried to understand but couldnt
The *
is not part of the function name. It signifies the return value of the function, which is in this case a pointer (because of the object-of *
operator) to struct entry
.
It can be written as any of the following:
1) struct entry *function(...)
2) struct entry* function (...)
3) struct entry * function (...)
Which one you use is up to you.
For starters there is a typo in the first parameter declaration. Instead of
Struct entry *listPtr
there must be
struct entry *listPtr
^^^^^^
The confusion is due to the placement of the symbol *
in the declaration
struct entry *addentry (struct entry *listPtr, int value){ }
Actually the following function declarations are equivalent
struct entry *addentry (struct entry *listPtr, int value){ }
struct entry * addentry (struct entry *listPtr, int value){ }
struct entry* addentry (struct entry *listPtr, int value){ }
In all the function declarations the function name is addentry
and the function return type is the pointer type struct entry *
.
You could even declare the function like
struct entry * ( addentry (struct entry *listPtr, int value) ){ }
It seems the function adds a new value to a list and returns the possibly updated pointer listPtr
within the function to the caller.