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. Dynamic Array Resize with Class Handles

VLSI DV Interview Puzzles · All levels

Dynamic Array Resize with Class Handles

Explain why changing `da[0].v` also changes `db[0].v` after resize-copy.

On this page

    Puzzle

    Difficulty: Hard · Puzzle 4 of 6 · Topic: Queue and Array Puzzles

    Explain why changing `da[0].v` also changes `db[0].v` after resize-copy.

    Code

    p4.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    class item;
      int v;
      function new(int v); this.v = v; endfunction
    endclass
    
    module p4;
      item da[];
      item db[];
      initial begin
        da = new[2];
        da[0] = new(10);
        da[1] = new(20);
        db = new[3](da);
        db[2] = new(30);
        da[0].v = 99;
        $display("da0=%0d db0=%0d db2=%0d", da[0].v, db[0].v, db[2].v);
      end
    endmodule

    Hint

    `new[N](old)` copies elements, but if element type is class handle, copied value is the handle.

    Step-by-step solution

    Diagram
    1) `db = new[3](da)` copies first two elements from `da` into `db`.
    2) Those elements are class handles, so db[0] and da[0] reference the same object.
    3) Updating `da[0].v` updates that shared object, visible through `db[0].v`.
    4) `db[2]` is independently constructed and remains 30.

    Answer

    Answer: da0=99, db0=99, db2=30

    Why candidates get it wrong

    Candidates conflate array copy (by value) with deep copy of objects stored in the array.

    Interviewer follow-up

    What code pattern gives deep-copy semantics for arrays of class handles?

    Related topics

    • Back to Queue and Array Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    20 / 210

    Next: Associative Array Iteration Order

    Up next

    Up nextAssociative Array Iteration Order

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Queue Mutation Plus Dynamic Resize
    • Queue Assignment Copies by Value
    • Locator Methods Return New Queues