I just learned the concept of a linked list in C, and tried implementing it. What I did was create a pointer `head`, and a pointer `itr`. To create a new node I would initialize a node normally (without using pointers), and then attach a pointer to it.

```
struct node temp;    //A single node contains a value 'num' and a pointer to the next node.
temp.num=x;
temp.next=NULL;

if(head==NULL){
    head=&temp;
}
else{
    itr=head;
    while(itr->next!=NULL){
        itr=itr->next;
    }
    itr->next=&temp;
}

```

This method is not working, and based on my limited knowledge of pointers in C, I cannot figure out why. I know that the right way to do it is by using malloc to create new nodes, but I need to know why this method does not work.

Full Program:

```
#include <stdio.h>

struct node{
    int num;
    struct node *next;
};

int main(){
    struct node *head=NULL;
    struct node *itr;
    struct node temp;

    int choice;
    printf("1. Enter new Node, 2. Traverse all nodes, 3. Exit.");

    int x;
    while(1){
        printf("\nEnter your choice: ");
        scanf("%d", &choice);

        if(choice==1){
            printf("Enter value: ");
            scanf("%d", &x);

            temp.num=x;
            temp.next=NULL;

            if(head==NULL){
                head=&temp;
            }
            else{
                itr=head;
                while(itr->next!=NULL){
                    itr=itr->next;
                }
                itr->next=&temp;
            }
        }

        else if(choice==2){
            if(head==NULL){
                printf("Empty List");
                continue;
            }
            printf("The values are: ");
            itr=head;
            printf("%d ", itr->num);
            while(itr->next!=NULL){
                itr=itr->next;
                printf("%d ", itr->num);
            }
        }

        else{
            break;
        }
    }
}

```