ProgrammingHardProduct company OA

What is printed?

What is printed?
printf("%d %d %d", atoi("42abc"), atoi("  -7x"), atoi("x9"));
  1. A. 42 -7 9
  2. B. 42 0 0
  3. C. 0 -7 0
  4. D. 42 -7 0

Correct answer: D. 42 -7 0

atoi skips leading white space, reads an optional sign and then as many digits as it can, stopping at the first non-digit. "42abc" gives 42, " -7x" gives -7, and "x9" has no leading digits at all, so it gives 0; atoi does not hunt for digits later in the string.

More C Programming questions

Exams that ask this topic