Thing I've got a little procedure that could do that, but you know the simplest thing I could do is to say well, gee, wait a minute, why don't I just check to see if these are the same thing?
这两个点是同一个点么?,我已经写了一小块代码,可以提供这个功能,但是你知道的我可以做的,最简单的事情就是说好,嗯?,等等,我为什么不直接去看看,这两个东西相等不相等呢?
If you have a set of blocks, mechanical, physical blocks,and I tell you to build something and I say, oh, by the way, you have to cut the blocks in smaller pieces, you are going to get angry, aren't you?
如果你要一个区块,力学的,物理区块,我告诉你要去建造东西,我说,顺便说一下,你必须将一整区块切成小块,你会生气,不会吗?
Well, again, just as I said verbally a moment ago, if you're going here, you're literally touching, trying to read or change memory that's beyond the boundaries of a chunk of memory that you're supposed to be touching based on its length.
嗯,再次强调,就像我刚才说的,如果你从这里出发,你将依次接触到,试着读取或者改变内存,如果超出了你可以使用的,内存块长度的界限。
And what is more, they actually invited me at once to join them, as though politics and I were a fit match.
更甚之,他们其实曾邀请过我加入他们,因认为我是块政治的料子。
And this would point to value, and this would point off someplace in memory.
需要多少个基本内存块,然后我就得知下一个元素的位置了。
You begin to realize that all of these big seemingly complicated pieces of software in websites that you use, if you just hone in on little pieces of them at a time and you realize oh I can do that and oh I can do that.
你开始意识到,你所登陆的网站上这些大而复杂的软件,如果你只对其中的一小块代码进行研究,你就会发现,哦,我也可以来做这个。
I don't know if I'd eat it if it were put in front of me, but anyways, I'm told that it looks something like this, that you have the custard with little fragments of plum inside.
我不知道,就算这东西曾经放在我面前,就算我吃过它,但是无论如何,但是有人告诉过我有些东西长得像这样,如同在一些小块的梅子,放在乳蛋糕里面。
It's just some random chunk of four bytes that happens to be available at this point in time, but I can put something there.
只是一些随机的四字节的内存块,在这里是可以使用的,但是我可以在那里放置东西。
Again, for those-- for whom this is blocked, I'm just dividing the rectangle into smaller squares which is to say that memory is addressable.
这是一整块的,我只是把它划分成一个个小区域,每个小区域都可以设定一个地址。
There's a whole bunch of blocks that we'll look at in more fun detail on Friday but I'm going to pick the easiest one here and I'm going to type Hello CS50 in this string, "Hello CS50", zooming in say how nice the puzzle pieces are nicely interlocked?
今天我们看到的各种图块,到下周五我会仔细讲解其中的精妙之处,但今天我只想举一个最简单的例子,我要在这儿键入字符串,放大窗口,然后看看这漂亮的图形和文字,是如何美妙地连结在一起的?
Yeah, if my machine will come back up, there we go. So, I'm going to now go ahead and write a little piece of code, and I put it here and I hope you can actually see these better this time, let me uncomment that region.
让我们写出代码来吧,好,如果我的电脑能回来的话,好了,那么,我要去写一小块代码,我把它放在这里以期望大家这次,能看的更清楚点。
And so when you start to poke around the puzzle pieces, you see that it can say things, we'll see movement in just a moment and sound and so forth, but at the end of the day, this is just like the program we used a moment ago for the sock exercise where we just hold Philip a step after step after step, do this, do this, do that, and yet, here too, we already see an opportunity for that thing we called the loop.
如果你认真看下这些拼图,你会发现它都是一些移动,并发出声音的功能块,就像我刚才的,练习程序一样,我们让飞利浦做这个动作,做那个动作,跟这里的情况一样,我们已经看到了称为循环的东西。
I'm doing a test there to say, x if the string x is less than the value of b, and x does not appear before b as strings, then I was going to do, oh, a couple of things, because they're at the same block level.
我正在做一个测试来看看,字符串,是不是小于b的值,而且x不在b之前作为字符串出现,如果是真的话我就要做,一系列的操作,因为他们是在同一个块等级上。
I'm going to go ahead and change to this Looks pallet over here.
我继续说,现在我们要改变这个写着Looks的图块。
It's reasonable because it's meant TMP for temporary purposes just to call it temp or T-M-P for short, X and I can define temp as -- why don't I set it as equal to X, initially, because now that I've stored X in a separate chunk of memory, I can now change its value and then I can say Y gets, not X, but temp, and so now I've actually swapped these values.
这是合理的,因为它是为,暂时的目的,只要叫它Temp或简称它为,我可以定义temp为--为什么我不把它设定为等于,最初的,因为现在我把X存储在一个单独的内存块中,我现在可以改变它的值,然后我说Y等于,不是X,而是temp,所以现在我交换这些值。
应用推荐