Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The atoi(), atol()atoll(), and atof() functions convert the initial portion of a string token to int, long int, long long int, and double representation representation, respectively. Except for the behavior on error (C23, s7.24.1 and , they are equivalent to

Code Block
atoi: (int)strtol(nptr, (char **)NULL, 10)
atol: strtol(nptr, (char **)NULL, 10)
atoll: strtoll(nptr, (char **)NULL, 10)
atof: strtod(nptr, (char **)NULL)

...

  • do not need to set errno on an error;
  • have undefined behavior if the value of the result cannot be represented (before C23; in C23 and later, their behavior is defined by the strto*()  functions);
  • return 0 (or 0.0) if the string does not represent an integer (or decimal), which is indistinguishable from a correctly formatted, zero-denoting input string.

...