0

I'm currently wrapping up an assignment for class and i've been able to figure out most of the curveballs the professor threw at me but i've hit this one and it just seems strange. It seems he's declared... a pointer that is also a function?

struct data_node {
   char name [25];
   int data;
   struct data_node *next;
   };

struct data_node *find_node (struct data_node *linkedListPointer, int num);

how would I go about using this pointer that is also a function? Do I just fill it out with what I want? Thank you for any advice and assistance in advance!

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ArkM
0

>It seems he's declared... a pointer that is also a function?
Nope, it's a function that returns a pointer. The closest thing to a pointer that's also a function would be a pointer to a function:

void (*fp) ( void );
0

Did you say that double sqrt(double x); is a double that is also a function? It's a prototype of a function named sqrt returning double value!

So you have a prototype (declaration) of a function named find_node with two parameters. It returns a pointer to (found) structure (probably, a node of a list). Example:

struct data_node* listroot;
struct data_node* found;
...
found = find_node(listroot,2009);
if (found == NULL) { /* not found */
    ...

You must declare all names before use them. You must include function prototype before call it.

Look at http://www.tenouk.com/Module4.html

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.