OK. So if we have variables, one of the questions we can ask is, what's the type of the variable.
好,如果我们有了一个变量,我们要问的问题之一就是,这个变量的类型是什么?
The square brackets here, meanwhile, say this is a special type of variable that's got multiple values inside of it.
这里的这个方括号,同时,说明这个是特殊的变量类型,里面有很多复合的值。
Because I might have written some code in which I'm expecting that integer particular variable to have an integer value.
因为我可能写了一些代码,来把一些,变量的类型,指定为。
s1 I have a variable called s1 and it's char * of type char * so here we go.
我有一个变量,它的类型是。
So one of the things I would like to suggest is that you develop some good style here, and in particular, don't change types arbitrarily.
所以我的建议是,你们要养成一些好的编程风格,尤其是,不要反复无常的改变变量的类型。
If somewhere later on in the code it shifts to string, I might not be manipulating that and getting actual values out, but not what I wanted, and it's going to be really hard for me to chase it back.
然后后面的一些代码,把变量类型变为了字符串,我可能不会通过实际操作,去取得实际的变量的类型,但是这并不是我想要的类型,而且对我来说把类型,变回去也很困难。
Now, what type of variable is this?
那么,这个变量的类型是什么?
You don't want to make those changes.
你不该改变变量的类型。
And the only thing that's differing is the name of the type and the name of the variable I'm using.
其中唯一的区别是数据类型的名字,和我使用的变量名字。
Well, unfortunately in C, you have to be ever so specific as to what you wanna put in the variable.
很不幸,在C语言里,给变量赋值之前,你必须搞清楚它的数据类型。
> David: At some point in time, I'm going to have to have declared the variable as a float before I can then hand it to printf as the insertion value for that format strength.
>,大卫:在一个特定的时间,我将需要,声明float类型这样的变量,那样我就可以把它打印出来,像是格式化优点的插入值。
Well, it turns out C, like a lot of languages, comes out of the box with a whole bunch of built-in variable types.
在C语言还有其他一些编程语言里,都会有一大堆,固定的变量类型。
So this line here declares a variable, just storage space called "x" and it's of type "int," which means an integer has to go in it.
这里的这条线声明了一个变量,一个叫做“x“的存储空间,它的类型是“int“,意思是里面存储的是整数型的数据。
i So I have up here at the top of my program a variable called i 0 of type int, and I have to initialize it up here to zero.
所以在程序的顶端我有一个int类型的变量,我需要把它初始化为。
So there's no mention of int, and yet we've been saying for the past couple of lectures, that anytime you declare a variable, you absolutely have to specify its type.
这里没有提及int,我们在前几个演讲中,一直讨论的东西,任何时候你声明一个变量,你必须指定它的类型。
int So whereas before I mentioned int, turns out if you wanna put a string in a variable, you have to say this is a string.
先不管我之前提到的,如果你想把一个字符串赋给某个变量,那你必须事先声明这个变量是string类型的。
And I'm storing the answer in a variable called "answer" that's of type float.
我把这个答案存储在一个float类型的,叫做“answer“的变量中。
应用推荐