I am trying to find the number of digits in a given number through the use of pointers.
This code below will give the correct output,
void numDigits(int num, int *result) {
*result = 0;
do {
*result += 1;
num = num / 10;
} while (num > 0);
}
However, if I change the *result += 1;
line to *result++;
, the output will no longer be correct and only give 0.
What is going on here?