VLSI DV Interview Puzzles · All levels
Case-Sensitive vs Case-Insensitive Compare
What do these boolean checks print?
Puzzle
Difficulty: Easy · Puzzle 3 of 6 · Topic: String and Casting Puzzles
What do these boolean checks print?
Code
systemverilog
module p3;
string a = "Reset";
string b = "reset";
initial begin
$display("eq=%0d", a == b);
$display("compare_eq0=%0d", a.compare(b) == 0);
$display("icompare_eq0=%0d", a.icompare(b) == 0);
end
endmoduleHint
`==` and `compare` are case-sensitive. `icompare` ignores case.
Step-by-step solution
diagram
1) `a == b` is false because uppercase R differs from lowercase r.
2) `compare(...) == 0` is also false for same reason.
3) `icompare(...) == 0` is true because it performs case-insensitive comparison.Answer
Answer: eq=0, compare_eq0=0, icompare_eq0=1
Why candidates get it wrong
Candidates often remember one compare API and assume all string compare methods share case behavior.
Interviewer follow-up
Which method would you use to implement case-insensitive sort ordering?