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. Queue Assignment Copies by Value
On this page

    VLSI DV Interview PuzzlesAll levels

    Queue Assignment Copies by Value

    After assignment and independent mutations, what are `q1` and `q2`?

    Puzzle

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

    After assignment and independent mutations, what are `q1` and `q2`?

    Code

    p2.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    module p2;
      int q1[$] = '{1,2,3};
      int q2[$];
      initial begin
        q2 = q1;
        void'(q1.pop_front());
        q2.push_back(4);
        $display("q1=%p q2=%p", q1, q2);
      end
    endmodule

    Hint

    Queues are unpacked value types, not class handles.

    Step-by-step solution

    Diagram
    1) `q2 = q1` copies queue contents into a separate queue.
    2) `q1.pop_front()` changes only q1 to `{2,3}`.
    3) `q2.push_back(4)` changes only q2 to `{1,2,3,4}`.

    Answer

    Answer: q1=' {2,3}, q2=' {1,2,3,4}

    How this was checked

    Checked by running the code in Icarus Verilog 13 and Verilator 5; the printed output supports the answer above. Elements printed one by one because Icarus cannot print a whole queue with %p. The %p layout is tool-specific; the queue contents 2,3 and 1,2,3,4 are what matter.

    Why candidates get it wrong

    `q2 = q1` copies the elements; a later `pop_front` on q1 does not touch q2, unlike a class handle assignment.

    Interviewer follow-up

    What collection type in SV would alias by handle instead of value? Model answer: none of the built-in containers does; only a class handle aliases, so a queue wrapped in a class object (or passed by `ref`) is shared by handle.

    Say it out loud

    I would say that assigning a queue copies the elements, so the two queues are independent. After the pop front on the first queue it holds 2 and 3, and after the push back the second holds 1, 2, 3 and 4. The trap is thinking it behaves like a class handle, where both names would see the change. Only a class handle aliases, so I would check whether anything is wrapped in a class or passed by reference.

    Related topics

    • Dynamic Arrays and Queues

    • Handles vs Objects

    • Back to Queue and Array Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    24 / 293

    Next: Pop from Empty Queue

    Up next

    Up nextPop from Empty Queue

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Dynamic Array Resize with Class Handles
    • Associative Array Iteration Order
    • Locator Methods Return New Queues