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

AboutContactPrivacyTerms
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
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • 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

VLSI DV Interview Puzzles · All levels

Queue Assignment Copies by Value

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

On this page

    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;
        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}

    Why candidates get it wrong

    Candidates sometimes project class-handle aliasing behavior onto queues.

    Interviewer follow-up

    What collection type in SV would alias by handle instead of value?

    Related topics

    • Back to Queue and Array Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    18 / 210

    Next: Pop from Empty Queue

    Up next

    Up nextPop from Empty Queue

    Sign in to save progress

    Practice this lessonReport an error

    See also

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