A queue is a data structure that stores tasks or items in the order they arrive. New tasks are added at the rear, and tasks are processed and removed from the front. This ensures the first task added is the first to be processed, following the FIFO principle. The front pointer shows the next task to process, and the rear pointer shows where new tasks are added. This structure helps manage tasks waiting their turn, like people in a line. The example code adds tasks 1 and 2, removes one, adds task 3, then removes another. The queue state changes step by step, showing how tasks move through the queue.