Q:

Why this recursive function only work when used ELSE

I made this function that returns the number of digits in an integer:
it works fine when I used ELSE to return the count 
int getIndex(int number, int count) {   // at first call count is 0
 number /= 10;
if (number > 0){

    getIndex(number,++count);

               }
else{
    return ++count;
    }   
}

but when I first tried to execute without ELSE statement I thought function will be called recursively till IF condition is not met and then only it will encounter the return statement 
And function will exit there as integer is returned, but 
actually 
if the number contains more than one digit, doesn't matter how many time it increase with recursive call  it outputs 2
Just curious where as to why I am getting my concept wrong

A:

it works fine when I used ELSE

Actually, the behaviour of the shown program is undefined. If the if branch is entered, then no return statement will be reached, and the behaviour of the program will be undefined.
When you remove the else statement and instead return unconditionally, the behaviour is well defined: The function will always return count + 1 or count + 2 depending on the value of number (which isn't correct).

Consider this, where do you use the value of the recursive function call? Nowhere; you simply discard the value. Would it make sense to return that value to the caller? Yes, it would. If only you returned within the if branch, the behaviour would be correct.
return getIndex(number,++count);

Then it won't matter whether the recursion-terminating branch is within else or not, it will only be executed if the if branch is not executed:

