Difficulty: Easy
Correct Answer: 3
Explanation:
Introduction / Context:strcspn returns the length of the initial segment of the first string that consists of characters not found in the second string. Once a character from the second string appears in the first string, the count stops, and that index is returned.
Given Data / Assumptions:
"India"."CuriousTab" (case-sensitive).strcspn("India", "CuriousTab").
Concept / Approach:
Scan "India" left to right until a character appears that is present in "CuriousTab". The function returns the count of characters before that first match.
Step-by-Step Solution:
Check characters in order: I (uppercase) not in "CuriousTab".n not in the second string.d not in the second string.i (lowercase) is in "CuriousTab".Therefore the initial non-matching span length is 3, so the function returns 3.
Verification / Alternative check:
Print strcspn outputs for intermediate prefixes to confirm behavior; also note the function is case-sensitive.
Why Other Options Are Wrong:
2 stops too early; 5 or 8 ignore the early match; returning -1 is not how strcspn signals matches.
Common Pitfalls:
Confusing strcspn with strspn, or forgetting its case sensitivity.
Final Answer:
3
Discussion & Comments