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
    • String and Casting Puzzles
      • String Substr with Runtime Class Cast
      • putc/getc Index Semantics
      • Case-Sensitive vs Case-Insensitive Compare
      • Enum Safety with $cast
      • Upcast, Virtual Dispatch and Downcast
      • String Number Parsing Stops Early
    • 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

←String and Casting Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. SystemVerilog Language Puzzles
  4. String and Casting Puzzles
  5. putc/getc Index Semantics
On this page

    VLSI DV Interview PuzzlesAll levels

    putc/getc Index Semantics

    After one character replacement, what are final string, length, and ASCII code?

    Puzzle

    Difficulty: Easy · Puzzle 2 of 6 · Topic: String and Casting Puzzles

    After one character replacement, what are final string, length, and ASCII code?

    Code

    p2.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    module p2;
      string s = "dv puzzle";
      int ch;
      initial begin
        s.putc(3, 8'h5f); // '_'
        ch = s.getc(4);
        $display("s=%s len=%0d ch=%0d", s, s.len(), ch);
      end
    endmodule

    Hint

    String indexing is zero-based and `putc` writes at an index, it does not insert and shift.

    Step-by-step solution

    Diagram
    1) Original index 3 is character `p` in `"dv puzzle"`.
    2) `putc(3,'_')` replaces `p`, giving `"dv _uzzle"`.
    3) Length remains 9 because replacement is in-place.
    4) Index 4 is `u`, whose ASCII code is 117.

    Answer

    Answer: s=dv _uzzle, len=9, ch=117

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. putc replaces in place so the length stays 9; Icarus 13 has no putc or getc.

    Why candidates get it wrong

    `putc` overwrites in place (length stays 9) and string indexing starts at 0, so index 3 is the `p`, not the space.

    Interviewer follow-up

    What does `s.getc(100)` return for out-of-range index? Model answer: 0 (run), and the string is not changed.

    Say it out loud

    I would count from 0, because string indexing starts at zero. Index 3 is the p, putc replaces it in place with an underscore, so the string is dv underscore uzzle and the length stays 9. Index 4 is u, whose code is 117. The trap is counting from 1 or thinking putc inserts. I would check the index range, since a call outside it does nothing.

    Related topics

    • Strings, Reals & Special Types

    • Back to String and Casting Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    30 / 293

    Next: Case-Sensitive vs Case-Insensitive Compare

    Up next

    Up nextCase-Sensitive vs Case-Insensitive Compare

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Enum Safety with $cast
    • Upcast, Virtual Dispatch and Downcast
    • String Number Parsing Stops Early