ProgrammingHard

A loop computes the number of decimal digits of n = 10^18 with while (n) { n /= 10; cnt++; }. What value does cnt reach?

  1. A. 18
  2. B. 19
  3. C. 20
  4. D. 1

Correct answer: B. 19

10^18 has 19 digits, and each division removes one digit until n becomes 0. The loop runs once per digit.

More C Programming questions

Exams that ask this topic