1. ## Confusing with pointer to structure...Please help me see the code

I'm reading through a data structure textbook. I'm doing the part of Linked list.
here's the code from the textbook:
I'm not clear with pointer.

what I'm confused is that the code created a pointer to the structure (*NodePtr)
Q1. Is NodePtr store the address of the structure??
Q2. Are top, np, last address of the structure??
Q3. here.....NodePtr makeNode(int);... does it returns an address of the structure which is np?? but following part np is used as a pointer??

Code:
```#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int num;
struct node* next;
}Node, *NodePtr;

main()
{
void printlist(NodePtr);
NodePtr makeNode(int);
int n;
NodePtr top, np, last;

top = NULL;
if(scan(%d, &n)!= 1) n=0;
while(n!=0)
{
np= makeNode(n);
if(top == NULL) top = np;
else last -> next = np;
last = np;
if(scanf("%d", &n)!=1) n= 0;
}

printList(top);
}

NodePtr makeNode(int n)
{
NodePtr np = (NodePtr)malloc(sizeof(Node));
np -> num = n;
np -> next = NULL;
return np;
}

void printList(NodePtr np)
{
while(np != NULL)
{
printf("%d\n", np->num);
np = np->next;
}
}```
from Data Structures in C. by Noel Kalicharan. page60 2. That is a typedef, that it's doing is linking the name NodePtr to the type of struct node * (pointer to node object).

Perhaps this will make it more clear:
Code:
```struct node{
int num;
struct node* next;
};

typedef struct node Node;
typedef struct node *NodePtr;```
The code above simply combines those 3 lines into a single statement. 3. Thank you for replying me!

Can I say these: Node and *NodePtr, these are a type of data which is struct node
so *NodePtr is the structure, NodePtr is the pointer to the structure, so does np, top and last

What is the difference between Node and *NodePtr?
when declare does it means NodePtr occupy a single cell that stores the address of the structure which is NULL/rubbish at that time
while system create a full struct Node space for Node? - I might expressing it in a confusing way - Am I thinking it in the right way??

so in the code
Code:
```NodePtr makeNode(int n)
{
NodePtr np = (NodePtr)malloc(sizeof(Node));
np ->num = n;
np ->next = NULL;
return np;
}```
why its not cast as (*NodePtr)? I'm so bad at pointers
like this
Code:
```char* buffer;
buffer = (char*)buffer(sizeof(char));``` 4. Originally Posted by xz1014
Node are *NodePtr, these are a type of data which is struct node
No, refer to nonpuz's code snippet in post #2. Node is an alias for struct node; NodePtr is an alias for struct node* (i.e., pointer to struct node). The *NodePtr syntax that you see is just syntax for the typedef to declare that NodePtr is an alias for struct node*. By itself, *NodePtr has no meaning as NodePtr is a type, so you cannot apply the dereference operator to it. 5. I just read the chapter again and I think I understand what you mean! Thank you!
so when I declare a pointer to the structure struct node. I can either do NodePtr np or Node* np. When I malloc space I can cast as either NodePtr or (Node*)?

so... What will happen if I don't use pointer to create linked list? Popular pages Recent additions 