title: C queue program not giving overflow error when its full
body: <p>This program is not giving "Queue Overflow" error message when its full. Why is that so? Is there something wrong with the qfull function? I even tried if(qfull(*r)==1). Even then its not working. It just keeps going on accepting numbers even when its full.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;process.h&gt;
  #define QUEUE_SIZE 5
  
  void insert_rear(int,int*,int*);
  void delete_front(int*,int*,int*);
  void display(int*,int,int);
  int qempty(int,int);
  int qfull(int);
  void main()
  {
      int f=0,r=-1,q[10],item,choice;
      for(;;)
      {
      clrscr();
        printf("\t\t\t Ordinary Queue Operation\n\n");
        printf("\t\t\t 1. Push\n");
        printf("\t\t\t 2. Pop\n");
        printf("\t\t\t 3. Display\n");
        printf("\t\t\t 4. Exit\n\n");
        printf("\t\t\t Enter your choice: ");
        scanf("%d",&amp;choice);
        switch(choice)
        {
          case 1:
              printf("Enter the item to be inserted: ");
              scanf("%d",&amp;item);
              insert_rear(item,q,&amp;r);
              continue;
           case 2:
              delete_front(q,&amp;f,&amp;r);
              break;
           case 3:
              display(q,f,r);
              break;
           case 4:
              exit(0);
           default:
              printf("\t\t\t Invalid Input - Try Again");
        }
        getch();
     }
  }
  
  
  
  
  
  void insert_rear(int item,int q[],int *r)
  {
      if(qfull(*r)==1)
     {
      printf("\t\t\t Queue Overflow\n");
        return;
     }
     q[++(*r)]=item;
  }
  
  
  
  
  
  void delete_front(int q[],int *f,int *r)
  {
      if(qempty(*f,*r))
     {
      printf("\t\t\t Queue Underflow\n");
        return;
     }
     printf("Pop successfull, item deleted = %d",q[(*f)++]);
     if(*f&gt;*r)
     {
      *f=0,*r=-1;
     }
  }
  
  
  
  
  
  void display(int q[],int f,int r)
  {
      int i;
     if(qempty(f,r))
     {
      printf("Queue is empty\n");
        return;
     }
     printf("\t\t\t Queue Container\n\n");
     for(i=f;i&lt;=r;i++)
      printf("\t\t\t |%5d|\n",q[i]);
  }
  
  
  
  
  
  int qempty(int f,int r)
  {
      return(f&gt;r)?1:0;
  }
  
  
  
  
  
  int qfull(int r)
  {
      return(r==QUEUE_SIZE-1)?1:0;
  }
  </code></pre>