So you're implementing this black box, and if its purpose in life is to actually return a value, you have to tell the compiler what kind of value to expect, and this is going to have ripple effects.
你在实现这个黑盒子,如果它的目的是,返回一个值,你必须告诉编译器你期望的是什么类型的值,这个将是一个连锁反应。
And then the only other difference is obviously, it's a function I need to return a value.
然后还剩下一点明显的区别,对于方法我要有返回值。
And if it returns a value, you've got to do something with that return value too, much like we did up here.
如果它返回了一个值,你便用那个返回值,做一些事情,就像我们刚在上面做的。
But it's a valuable thing. It says, in each case, I return some useful value from this procedure.
但是这就是变量,是在每个例子中,我从这个程序中返回了一些有用的值。
I don't have to go read what it printed out in the screen. This has returned a value that I can use. Because I could do a test to say, is this a return value? If it's not, I'll do something else with it. So the binding is still there, it simply doesn't print it out.
我不想读到屏幕中打印出来的这行字,程序返回过一个我能够使用的值,因为我可以做个小测试,来说明这是否是返回的值,如果不是,我可以做一些其它的事,而这个绑定依然在这儿,没有打印任何东西。
And it's up to me to put that return value in a variable.
那个放在变量中的值是取决于我所赋的值。
It's defined in CS50's library; its sole purpose in life is to ask the user for a floating point value and return it.
它被定义在CS50的函数库中,它的唯一目的是,向用户询问一个浮点数的值,然后返回它。
And the reason that we now on the second line have the equal sign is because this function GetString has what's called a return value.
我们之所以,在第二行代码GetString前面加上等号,是因为这个函数会带回一个,返回值。
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值,也就是我们想要的,对吧?,它就承载了我们想得到的值。
应用推荐