Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
    • Datatype and Bit Puzzles
    • Fork Join Puzzles
    • Queue and Array Puzzles
      • Queue Mutation Plus Dynamic Resize
      • Queue Assignment Copies by Value
      • Pop from Empty Queue
      • Dynamic Array Resize with Class Handles
      • Associative Array Iteration Order
      • Locator Methods Return New Queues
    • String and Casting Puzzles
    • SystemVerilog Language Puzzles: Tricky Q&A
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Queue and Array Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. SystemVerilog Language Puzzles
  4. Queue and Array Puzzles
  5. Pop from Empty Queue
On this page

    VLSI DV Interview PuzzlesAll levels

    Pop from Empty Queue

    What values are returned by `pop_front` and `pop_back` on an empty queue?

    Puzzle

    Difficulty: Easy · Puzzle 3 of 6 · Topic: Queue and Array Puzzles

    What values are returned by `pop_front` and `pop_back` on an empty queue?

    Code

    p3.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    module p3;
      int q[$];
      int a, b;
      initial begin
        a = q.pop_front();
        b = q.pop_back();
        $display("a=%0d b=%0d size=%0d", a, b, q.size());
      end
    endmodule

    Hint

    SV returns default value of element type when popping from an empty queue.

    Step-by-step solution

    Diagram
    1) Queue starts empty.
    2) `pop_front()` returns default `int` value 0 when queue is empty.
    3) `pop_back()` on still-empty queue also returns 0.
    4) Queue size remains 0.

    Answer

    Answer: a=0, b=0, size=0

    How this was checked

    Checked by running the code in Verilator 5 and Icarus Verilog 13; the printed output supports the answer above. A conforming tool returns the default value 0 for int. Icarus returns x for an empty-queue pop of int, which the LRM does not call for (it requires the default value 0).

    Why candidates get it wrong

    Popping an empty queue is not a fatal error: it returns the element type's default (0 for `int`), and some tools only warn (Icarus even returns x for an int queue, which is non-conforming).

    Interviewer follow-up

    How would behavior differ for `string q[$]` when popping empty? Model answer: it returns the empty string ""; for a 4-state element type such as `logic [3:0]` it returns x (run on Icarus: [] and xxxx).

    Say it out loud

    I would say that popping an empty queue is not fatal and it returns the default value of the element type, which is 0 for an int. So both pops give 0 and the size stays 0. The trap is that tools differ: some only warn, and Icarus even returns x for an int queue, which is not what the standard says. I would check the size before every pop in real code.

    Related topics

    • Dynamic Arrays and Queues

    • Back to Queue and Array Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    25 / 293

    Next: Dynamic Array Resize with Class Handles

    Up next

    Up nextDynamic Array Resize with Class Handles

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Queue Mutation Plus Dynamic Resize
    • Associative Array Iteration Order
    • Locator Methods Return New Queues