Hello , Please what does the second typedef statement do,

struct listnode{
char data;
struct listnode *nextPtr;
};

typedef struct listnode Listnode;
typedef ListNode *ListNodePtr;

what is the difference between

ListNodePtr *sPtr;
      and
ListNodePtr startPtr;

Please explain what the second Line of Code would do please

startPtr = NULL;
ListNodePtr *sPtr = &startPtr

Recommended Answers

All 6 Replies

typedef ListNode *ListNodePtr;

means you are making an alias for "ListNode*" as "ListNodePtr".
So when you declare avariable of type "ListNodePtr" it will mean you are declaring a variable of type "ListNode*".

ListNodePtr *sPtr;
ListNodePtr startPtr;

You will get the difference once you replace the alias name with the original data types.

ListNodePtr *sPtr = &startPtr

Expand the alias for "ListNodePtr" you will know what it is doing.

does declaring a variable of type ListNodePtr or ListNode* make the variable a pointer?

yes it does.

sorry for all the ridiculous questions , but i really want to clear my doubts and get this right .
if declaring a variable of type ListNodePtr makes it a pointer, then declaring it with type ListNodePtr* makes it ?(a double pointer)?

you are right again.

You have been given the same answers in two different C forums, I hope that's enough cross posting on this subject.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.