Ad
  • Default User Avatar

    p is declared and initialized in the initialization statement of the for loop:

    for (char i = 0, *p = y; ...; ...) {
    
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    this fixes the symptoms, not the condition. your code would still fail for very large ints. UINT_MAX is just twice as large as INT_MAX, not 10 times as large. if you want to count the number of digits of a number, you should rather divide than multiply

  • Default User Avatar

    for (int i = 10; i <= n; i *= 10, digits++)

    if n is very large, there is no power of 10 larger than n that can fit inside i, so this loops forever.
    for example, if n is 2,000,000,000, the next largest power of 10 is 10,000,000,000, but INT_MAX aka 2 ** 31 - 1 is 2,147,483,647

  • Custom User Avatar

    Hi. The description may be unclear about that, but there is no obligation to use recursion to solve this problem. However, it's possible to use recursion to solve this problem. You should try to print stuff from your code to try to catch when your code doesn't act as it should (use printf).