So just as we had to escape things with backslashes in an awkward way, same deal with percent in this context.
所以就像我们采用笨拙的方式来用反斜杠来避免一些东西,在这个背景下对百分号做相同的处理。
Right, so there's that special sentinel value that's back slash zero, which we'll start to see more explicitly now.
对的,这里有一个特殊的值“反斜杠0“,我们等下会更了解它。
I could have done this in another way but I am going to just be extra deliberate so I make sure that this copy ends with back slash zero and voila, now, I have a copy.
我可以用另外一种方式来处理,我确保这个拷贝由反斜杠0结尾,那样,现在我得到了一个拷贝。
It gets really kind of trippy if you wanna output a backslash, \ you can't just use the backslash, \\ you need to use backslash backslash because otherwise a single backslash is confused with the so called escape character.
如果你想输出一个反斜杠,估计又得迷糊了,实际上,你不能直接用,而是要,否则一个\可能会被误认为,是转义字符。
n If you want a literal percent, it's %% and then backslash n.
如果你想要一个百分比常量,就用%%,然后,反斜杠。
This backlash N, it's also a recurring theme and not just in C but in PHP, JavaScript, other languages as well.
还有反斜杠n,不仅C语言里有,在其他语言像PHP,JavaScript等都会碰到。
The back slash zero, right?
是反斜杠0,对不?
So it does that for us so that you can get away with just knowing the address of the first byte and it will make sure that you know when to stop by including the special value so, in fact, get the string if you type in a three-letter word, we allocate four bytes no matter what because we need an additional byte 0 for this special sentinel value back slash zero at the very end.
它为我们做了这些事情,这样我们就可以,通过第一个字节的地址,它还可以通过包含一个特殊的值,来保证在哪里停止,如果你输入了一个三个字母的单词,就可以获得那个字符串,不管怎样,我们分配四个字节,因为我们在末端需要一个额外的字节,来保存这个特殊的标志值--反斜杠。
I print F, I backslash N, just to pretty up the screen, ArgC I then iterate from, I equal zero up to Arg C; so Arg C is the convention.
我键入printf,反斜杠n,来使屏幕变得美观点,然后i开始迭代,从i等于0增加到;,所以ArgC是一个约定。
printf So thus far, the things I put David between quotes are just simple things like David or David backslash N, but what if I want to do call my self David in quotes, right?
像我们前面提到的,我们把要显示的东西放在双引号之间,譬如,或,David反斜杠n,但是如果我自己的名字本来就叫,“David“
So you have what are called escape characters like backslash N that is the shorthand notation of telling the computer put a new line character here.
幸亏我们有一些类似反斜杠n的转义字符,这只是一种简化方式,用来告知电脑要在这新添一行。
- There's no backslash n -- that would have forced the cursor on to the next row.
但没有“反斜杠n“,反斜杠n是用来使光标移到下一行的。
Notice I close the quotes after I'm putting a new line-- after I'm putting this new line, name but then to the right hand side is comma name.
注意反斜杠n后面加上后引号-,后引号,再右边就是逗号。
This is what you typed into the white box in Scratch and anyone perhaps already familiar, the backslash N is the shorthand way of saying what?
这也是你们在Scratch的白色输入框里要填入的东西,也许已经有人知道,反斜杠n代表某种简写方式吧?
If n is greater than zero, I decided I would say, "You picked a positive number, backslash n," so put the cursor on the next line, else if n was not less than zero, I say, "You picked a negative number, backslash n."
如果n比0大,我就决定来说:,“你选择了一个整数,反斜杠n“,所以你把光标,放在下一行,另外如果n不小于0,我说:,“你选择一个负数,反斜杠n“
You can certainly hit Enter but as we saw-- seen that very quickly makes a mess of your code and such and so backslash N is new line.
你也可以敲回车键-,但是会让你的代码看起来乱七八糟,反斜杠n就是换行符。
I mean, you'll play with it in great-- with great delight this semester, you will see that backslash N is the standard in any text file for creating what we know as new line characters.
我是指,这学期,你们会很高兴-,和它打交道,同时你们也会看到,在任何文本文件里,反斜杠n已经是,换行的代名词了。
> >> David: Yeah, so I didn't have my "backslash n."
>,【无法辨认的声音】,>>,大卫:是的,我没有加入“反斜杠,n“
Let me go ahead and call print F. I'm going to say A equals A and then I need a percent D, backslash, comma A; so this is a little bit of -- more syntax than would be nice, %d but I'm just saying, literally, A equals percent D, and I'm plugging in the value of A for percent D.
我们继续调用printf,我说明A等于,然后我需要%d,反斜杠n,逗号;,所以这个有点--偏向逻辑的,而不偏向美观的,但是我刚说了,字面上,A等于,我用%d插入了A的值。
应用推荐