Circular buffer implementation using linked list I'm a beginner with C.
The below is the implementation of circular buffer using linked list. Please review my code and suggest any improvements to make it efficient or to improve in coding style.

#include&lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

struct link_list
{
    int item;
    struct link_list *next;
};

struct link_list *read=NULL;
struct link_list *write=NULL;
int size=NULL; //buffer size
static int p_size=0; //present size of buffer

void enqueue()
{
    int value;
    struct link_list *newnode=(struct link_list*)malloc(sizeof(struct link_list));
    printf("Enter new value : \n");
    scanf("%d",&amp;value);
    newnode-&gt;item=value;
    newnode-&gt;next=NULL;

    if(read==NULL&amp;&amp;write==NULL)
    {
    read=write=newnode;
        p_size++;
    }
    else
    {   
        if (p_size&lt;size)
        {
            printf("still buffer not filled\n");
            write-&gt;next=newnode;
            write=newnode;
            p_size++;
        }
        else
        {
            printf("size is exceeded\n");
            write=write-&gt;next;
            read-&gt;item=value;
            read=read-&gt;next;
        }
        write-&gt;next=read;
    }
    write-&gt;next=read;
}


void dequeue()
{
    int val;
    struct link_list *ptr=read;
    if(read==NULL)
    {
        printf("Stack is empty \n");
    }
    else
    {
        if (p_size&gt;0)
        {   
            val=read-&gt;item;
            read=read-&gt;next;
            free(ptr);
            p_size--;
            printf("removed %d\n",val);
        }
        else 
        {
            p_size=0;
            read=write=NULL;
            printf("nothing else to remove\n");
        }
    }   
}


void print()
{
    printf("psize= %d\n",p_size);
    struct link_list *ptr=read;
    if (read==NULL)
    {
        printf("nothing in queue\n");return;
    }
    if (p_size==0) 
    {
        printf("stack empty\n");
        return;
    }
    else
    {
        while (ptr!=NULL)
        {
            if (ptr!=write)
            {
                printf("Value= %d Aderss= %p Next Address= %p\n", ptr-&gt;item,ptr, ptr-&gt;next);
                ptr=ptr-&gt;next;
            }
            else
            {
                printf("Value= %d Aderss= %p Next Address= %p\n", ptr-&gt;item,ptr, ptr-&gt;next);
                break;
            }
        }
        printf("read--@Value= %d Aderss= %p Next Address= %p\n", read-&gt;item,read, read-&gt;next);
        printf("write--@Value= %d Aderss= %p Next Address= %p\n", write-&gt;item,write, write-&gt;next);

    }
}


void main()
{
    char ch;
    int val;
    int loop=1;
    printf("enter the buffer size---\n");
    scanf("%d",&amp;size);
    while(loop==1)
    {
        printf("select a) to add to queue, b) to dequeue s) sort p) print x)ext\n");
        scanf("%c",&amp;ch);
        switch(ch)
        {
            case 'a':
                enqueue();
                break;
            case 'b':
                dequeue();
                break;
            case 'p':
                print();
                break;
            case 'x':
                loop=0;
                break;
        }
    }
}
Bug
When you dequeue the last element, this code will run with p_size being 1:

   if (p_size&gt;0)
    {   
        val=read-&gt;item;
        read=read-&gt;next;
        free(ptr);
        p_size--;
        printf(&quot;removed %d\n&quot;,val);
    }


The result of this code is that the last element will be freed, but read and write will still be pointing at it, because the list was circular.  Then the next time you call enqueue(), it will use those stale pointers to add to the list.
To fix this problem, you should clear the pointers to NULL when you dequeue the last element.