Well, it turns out on most computers an address of the location and memory, aka a pointer, is itself 32 bits.
好的,它是一个计算机内存地址,或者说一个指针,占32位。
Now, if I've asked the user for a string and then a moment later I ask the user for another string, well, they're going to end up in different locations in memory just by nature of get string.
现在,如果我要用户输入一个字符串,一会儿之后我要用户输入另一个字符串,他们最终是在,不同的内存地址中。
Once I've got that, I can now start giving some variable names, sorry not, rephrase that, I can give some attributes, I can give some characteristics to these classes.
还有个指向内存中地址的指针,我还可以命名这个指针,因此cp1和cp2都是,指向它们的指针,一旦我创建了它类,我就可以开始赋予。
Not by some very arcane numeric address inside my computer's memory, but by a symbol, by a name.
不是通过一些在我电脑内存中的神秘的数字地址,而是通过一个符号,一个名字。
Its name is malloc for memory allocation and what malloc does for us is we say, hmm, the user has typed in a three-letter word.
它为我们分配内存地址,它为用户输入的3个字母单词,分配地址。
That is the address in memory in the heap of the first byte that the user typed in.
那是用户输入的字符串第一个字节,内存中堆的地址。
2 3 Down here we said this is like 4, 5, 6 and 1, 2, 3 so this is going to be memory location 7, 7, 7, 7, 1 whatever.
在这下面,这是,4,5,6,和,这将是内存地址,7,7,7,7,1,不管是什么。
Now finally swap has the ability, the power, to modify memory that isn't his own, that's not in his own scope because we've passed it in by address.
最终swap有能力,来修改不属于它的内存,不在它的作用域中,因为我们是通过地址传递的。
Well, maybe this ended up at location 7, 8, 7 8 9 9 so what's really in x is the number 7, 8, 9, which is the address in memory, but again, uninteresting.
嗯,可能这个在地址7,8,9结束,那么在x中实际上是数字,那是内存中的地址,但是,那是没有什么用的。
I'm going to delete that arrow and actually draw s2 as pointing to this chunk of memory because whereas before this sequence of chars might have lived at address 71 or whatever, well, this one might live at 91.
我不会把那个箭头删除,实际上我画了s2作为,这块内存的指针,因为,这个字符序列存储在地址71或其它的地方,这个可能存储在91的地方。
I mean what if you're running so many things, what if the user has copied and pasted their thesis and just pasted it at the blinking prompt such that you're now out of memory because your computer is somewhat limited in memory so get string cannot possibly return all those characters or fit all of those characters in memory and return to you the address of the first.
如果你运行了很多程序,假使用户复制粘贴了他们的论文,只是粘贴在光标提示符那里,这样就出现了内存不足,因为你们的计算机的内存是有限的,所以GetString不可能返回所有的字符,或者保存这些字符到内存中,并且返回第一个字符的地址。
应用推荐