So there's a return branch on every possible path through the code. And that's valuable, it's something you want to think about as your right your own.
所以代码中每条可能的路径,都会有一个返回值分支,这是非常有价值的,当你自己写程序的时候也应该考虑这件事。
OK. Note, by the way, if I chase through each possible path, like there's some IFs in here, if there's some places to go, at least in this piece of code, every possible path through this code ends in a return. And that's a good programming discipline, to make sure that happens.
注意一下,如果我跟进每一条可能的路径,像是这里的,起码在这段代码中就有很多走向,这段代码中的每一条可能路径,在结尾都会返回一个值,这就是一条很好的编程定律,请确保这样做。
So, after the second line for code here char * s1 gets the return value of get string this is what the state of our world looks like.
在第二行之后,这个代码char,*s1,等于GetSting的返回值,这就是它看起来的状态。
X I'm passing an X, and yet I'm also assigning the return value to X. So just intuitively what's going to be the effect of this one line of code?
我传一个X,之后我把返回值赋值给,很明显,这一行代码,将会产生什么作用?
So this line or these lines of code up here are arguably constant time steps to say if N is less than 2 in return, that it will always take maybe one step, maybe two steps, some number of fixed CPU cycles.
如果N小于2并返回,那么这些行所对应的代码,通常只需要执行一步,或者两步,具体数字与CPU周期有关。
Now, the one that we're most interested in ANS is the one where, in fact, it gets out ANS, so you see down here in the code, there's a spot where it's going to return the value of ANS, which is what we want, right? That's the thing that holds the value that we intended to have.
现在我们最感兴趣的是这个,事实上它返回的是,所以你看这段代码,在这里返回ANS值,也就是我们想要的,对吧?,它就承载了我们想得到的值。
应用推荐