0

for example:

struct entry *addentry (Struct entry *listPtr, int value){ }

why does the name have a *

I tried to understand but couldnt

Déjà vu
  • 28,223
  • 6
  • 72
  • 100

2 Answers2

2

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.

Harith
  • 4,663
  • 1
  • 5
  • 20
0

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335