Concept Flow - String to Integer atoi
Step 1: Skip spaces
i=0,1 → ' ' skipped → i=2
Step 2: Read sign
s[2]='-' → sign=-1 → i=3
Step 3: Accumulate digits
s[3]='4' → result=4
Step 4: Apply sign + clamp
-1 × 42 = -42
C's atoi processes the string in four strict sequential steps: skip whitespace, detect optional sign, accumulate digit characters left to right, then apply sign and clamp to INT_MAX/INT_MIN. The critical C-specific concern is overflow detection before multiplying — signed integer overflow is undefined behavior in C.
