They're pretty small right now, but supposed there could be more numbers, so let me increment my right hand.
现在它们都很小,但假定它包含更多的数字,我以右手的增量示意。
Anything where you're actually keeping track of something like a score that's having a variable that you increment -- plus, plus, or decrement, minus, minus, using the appropriate puzzle piece could certainly be compelling.
你需要保存像分数这样的事物时,你就需要一个变量,它可以自加,++,或者自减,要使用正确的拼图。
And when I'm done with the whole thing, before I end the increment of the variable, you know, when I'm done, I'm just not returning anything out.
在循环外面初始化它,然后做一个终结测试,然后在循环内部有一个指令集,在这个例子中,就是对余数做检查,然后显示信息,当我完成了整个循环。
The exact shape of the curve is subject to discussion, but the point of diminishing marginal utility is that, as you get more and more money, the increment in utility for each extra dollar diminishes.
这条曲线的确切形状还有待讨论,但是边际效用递减规律的重点在于,你得到的钱越多,每额外的一美元的增长效用会相对减小
But here, as we saw in week zero with the shoe example putting on socks, I have to increment this variable explicitly myself.
但是这里,像我们上周看到的,鞋子穿在袜子上,我需要亲自明确地增加这个变量。
My prototype, again, so that I can use it later increment without the compiler wondering what is this increment that you're referring to because it's not otherwise been declared.
我的函数原型,再次强调,我可以以后使用它,这样编译器就不会疑惑这个你提及的,是什么,因为是没有,被声明的。
increment Well, here, I'm calling my own function, increment.
这里,我调用我自己的函数。
increment I then declare increment early on.
在之前我声明了。
Implicit declaration of function increment.
函数增长的隐式说明。
It does, in fact, successfully increment X, because at this point in the story, X was not scoped to main.
它实际上成功的增加了X的值,因为在这个地方,X不是main中的范围。
But here's a new and improved, I think, version of increment; ++ returns nothing, takes nothing, but it does perform plus plus, but I did something stupid.
但这里是一个新的,改进了的increment版本;,没返回值,没输入值,但它执行的是,但是我做了件愚蠢的事情。
Now if you call a function, swap like increment or cube or swap, or in this case, foo, those variables are the parameters to that function, end up getting stored next in memory.
现在如果你调用一个函数,像increment或者cube或者,或者在这个例子里,foo,这些变量都是,函数的参数,在内存中存储。
So putting back that prototype allows me to compile this, because I'm saying proactively to the compiler hey, you're going to see a function called increment.
把那个原型放回原处使我能够编译它,因为我提前向编译器打了招呼,将看到一个叫做increment的函数。
So even though increment is obviously increment declared and defined in this function, it's later; so it's too late for me to use it in main.
很明显,即使在这个函数中,已经声明和定义;,也太迟了,以至于,我在main函数中不能使用它。
It makes sense to me logically that I want to see it first when I open the file; so I scroll on down but only later is increment declared.
这个逻辑上对我是有意义的,打开文件的时候,我想先看到它,所以我向下翻,之后才声明increment函数。
And then on the right hand side I++, we saw that in pseudocode with our socks example last week that just says increment I.
然后是最右边的i++,我们上周在socks例子的伪代码中,曾经见到过,不是么?只是代表i加1而已。
X So here I'm declaring another variable called X, and this is totally legitimate because I already know that if I'm implementing a function like swap or increment, I can absolutely take input.
这里我声明另一个变量,这个完全是合法的因为我已经知道,如果我执行一个像swap,或,increment的函数,我完全可以携带输入。
But notice unlike a for loop, if you want to declare a variable or increment or decrement to variable, you've got to do that yourself.
但请注意不像for循环,如果你想声明一个变量,或者变大或变小一个变量,你需要自己完成。
So this function increment takes nothing, returns nothing, and yet it does something.
所以increment函数不带入参,也不返回值,它也没做什么。
You do the math correctly, increment returns.
你正确地做了算术,increment返回。
So pictorially, it's as though there's now some other part of the blackboard here, maybe way up here where I can put anything I want that's accessible to main, that's accessible to swap, that's accessible to increment or any other function I might implement because it is, in fact, global.
绘画般地,它是在这里黑板上的其他部分,可能在这里的上面,我在哪里可以放置这些东西,使它们可以被main函数使用,可以被swap函数使用,可以被increment函数使用,或者我所实现的其它函数,因为它实际上是一个全局变量。
And when you call a function, one of the things X that happens is whatever your passing in, for instance, X, ; and if this is A, this thing gets copied into A; so at that moment in time of calling increment, I actually have two copies of the same value in memory but they're referred to by different names.
当你调用一个函数,其中发生的一件事情是,不管你输入什么,比如,或者是A,它把这个东西复制到A中;,调用increment的时候,实际上在内存中,有两个同样的值的内存块,但是它们有不同的名字。
应用推荐