Pointer to the null-terminated string to be converted to a `double`. The string may represent a floating-point value, optionally preceded by whitespace and a sign.
2nd Parameter Type : char **
A pointer to a pointer to a null-terminated string. Commonly used in functions like `strtol` and `strtok_r` to store the address of the first invalid character or to maintain state across function calls.
2nd Parameter
Pointer to a pointer that will be set to the character after the last valid character used in the conversion. Can be `NULL` if this information is not needed.
Read more about parameters of strtod in parameters section
The strtodfunction in C language Converts the initial portion of the string to a double-precision floating-point number.
The strtod function converts the initial portion of the string pointed to by nptr to a double. It skips leading whitespace, converts the subsequent characters as part of the number, and stops at the first character it cannot recognize as part of a number. If endptr is not NULL, it stores the address of the first invalid character in *endptr.
The strtodfunction takes 2
parameters:
•
const char * `str`: Pointer to the null-terminated string to be converted to a `double`. The string may represent a floating-point value, optionally preceded by whitespace and a sign.
•
char ** `endptr`: Pointer to a pointer that will be set to the character after the last valid character used in the conversion. Can be `NULL` if this information is not needed.
Converts the initial portion of the string `str` to a `double` value. If `endptr` is not `NULL`, it is set to point to the first character after the converted value. Returns the converted `double` value or `0.0` if no valid conversion could be performed. Handles special values like `INF` or `NAN` if supported.
The strtod function return value :
Returns the converted double value
If no conversion could be performed, 0
0 is returned
If the correct value is outside the range of representable values, HUGE_VAL (with the correct sign) is returned and errno is set to ERANGE
Output
This example demonstrates basic usage of strtod to convert a string to a double and identify the remainder of the string.