The standard C library functions strtof
and strtod
have the following signatures:
float strtof(const char *str, char **endptr);
double strtod(const char *str, char **endptr);
They each decompose the input string, str
, into three parts:
- An initial, possibly-empty, sequence of whitespace
- A "subject sequence" of characters that represent a floating-point value
- A "trailing sequence" of characters that are unrecognized (and which do not affect the conversion).
If endptr
is not NULL
, then *endptr
is set to a pointer to the character immediately following the last character that was part of the conversion (in other words, the start of the trailing sequence).
I am wondering: why is endptr
, then, a pointer to a non-const
char
pointer? Isn't *endptr
a pointer into a const
char
string (the input string str
)?