Skip to content

Parse an integer · ⁨解析整数⁩

English

Parse an integer

Turn a string like "-123" into the number -123, by hand — the job atoi does. Read an optional leading - to fix the sign, then build the value digit by digit: each new digit means result = result * 10 + digit. A character converts to its digit value with c - '0'.

中文

解析整数

把像 "-123" 这样的字符串手动转换成数字 -123 —— 也就是 atoi 做的事。先读取可选的前导 - 来确定符号,然后逐位构建数值:每来一个新数字就 result = result * 10 + 数字。一个字符可以用 c - '0' 转换成它的数字值。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩