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

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

VLSI DV Interview Puzzles · All levels

putc/getc Index Semantics

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

On this page

    Puzzle

    Difficulty: Medium · 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

    Why candidates get it wrong

    Many candidates treat `putc` like insertion and incorrectly change length/index mapping.

    Interviewer follow-up

    What does `s.getc(100)` return for out-of-range index?

    Related topics

    • Back to String and Casting Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    24 / 210

    Next: Case-Sensitive vs Case-Insensitive Compare

    Up next

    Up nextCase-Sensitive vs Case-Insensitive Compare

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Enum Safety with $cast
    • Failed Class Cast Leaves Old Handle
    • String Number Parsing Stops Early