Can somebody explain me, how this works:
return ( factor ==
factor
counts all the way down from sqrt
to 2. If there is a factor which is divisible by the number
, it breaks out of the for loop. Thus factor
contains the one of the divisors of number. So the divisor is held by *firstFactor
and the second divisor is held by *secondFactorPtr
. Note that these are the same pointers which your main() function has passed to Factor
. So in the main() function you will find that factor1
and factor2
are populated with 2 factors.
If it does not find any factor greater than 1, then it contains 1 and breaks out of the for loop. If it does not find a factor, then the only factos are 1 and the number itself.