How does return work here?

前端 未结 5 588
野性不改
野性不改 2021-01-27 06:25

new question: but why the expression from n == number, from firstFactorPtr == factor1 ?

Can somebody explain me, how this works:

return ( factor ==

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 06:53

    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.

提交回复
热议问题