We won't make you write dramas like Pirandello, but we're going to try make you at least write good code.
我们的函数中的东西,我们不会让你去写皮兰德娄的荒诞剧,但是我们会教你写漂亮的代码。
Same way that I have multiplication or division as a primitive, functions are going to give me, or somebody else who wrote them for me as part of a library, a new primitive that I'm going to be able to use.
我在用乘法或者除法当做原语,这些函数,或者别人写程序库中的函数,将会给我返回一个,我能使用的新原语。
So, as an example, let's take argon, I've written up the electron configuration here, and let's think about what some of the similarities might be between wave functions in argon and wave functions for hydrogen.
所以作为一个例子我们来看看氩,我已经把它的电子构型写在这里,我们来考虑氩和,氢波函数之间的,一些相似性。
If you're writing a one line function, whose sole purpose in life is addition, and, clearly, this is about addition, well, then it's, in fact, A reasonable to use a shorter symbol like A, but I do have to specify it's type.
如果你在写一个一行的函数,它唯一的目的是,做加法,显然这是关于加法的,好的,实际上,用一个短的标识符是合理的,像,但是我必须指明它的类型。
Maybe they didn't write down the binomial distribution, but they explained the idea of insurance and it didn't sound right to the typical nineteenth century American woman.
也许他们并不会给客户写二项分布函数,但会向他们灌输保险的理念,但这看起来对19世纪的美国女性,并不奏效
And what's this little loop say to do? This little loop says I'm going to write a function or procedures that takes in two messages.
这个小循环是做什么的,这个小的循环是,我要写一个函数或者过程来接受两条消息。
And then I could also do a Gaussian one here, with the mean of and the standard deviation of volatility divided by 2.
然后我在这里再写一个高斯分布的函数,它的浮动值的平均值和,标准偏差值都除了2。
But for now, think of this as just another way to write a function call.
但是现在,把这当成是写函数,调用的另外一种方式就行了。
So it turns out that, main, yes, is the default function you write, at least in C, when writing a program.
结果是,main函数,是的,这是你写的默认函数,至少是在C语言中,当写程序的时候。
But very soon will you find that if you're writing programs with lots and lots of functions, and some might call these, and these might call these, you can come up very soon with scenarios where you can not order them top to bottom, because everything is comingled, and there's a lot of cross talk among all of your functions.
但是不久后你们会发现你们写的程序中,有很多很多的函数,有的函数调用这些函数,这些函数又调用另外的函数,你不能用脚本,把它们从上到下排序,因为所有函数相互混合,在你的函数中也有很多交叉。
As an aside, why are you able to use print F without writing out a prototype for it?
此外,为什么我们不用写printf的函数原型,而可以使用它呢?
But it's the really correct way to specify that this function takes no arguments is to actually write this key word "void."
但是这的确是正确的方法来指明,这个函数是没有参数,实际上是写了这个关键字“void“
I've got a little function here.
我在这儿写了一个小函数。
include stdio h The next line of code says include standard io.h which just as a little sanity check contains among other things, printf.
接着的一行代码写着,这个库文件包含一些我们常用的函数,譬如,printf函数。
The standard library, that first line of code, it's not strictly necessary but any time you use a function, a tool that someone else wrote that lives in that so called library, you do need that include line as we'll see.
标准库函数--第一行代码,严格来说,不是每次都要写的,但是一旦你调用某个别人写,的函数,而这个函数又恰巧位于标准库里面,你就要像我们看到的这样,把它include进去。
cs50 h It's not called standard io.h, it's called cs50.h. That's where the code we wrote for you will live and then we'll see how to do this in examples today onward but we wrote for you some tools, some functions that calls GetChar for get a character.
当然不是标准输入输出库了,而是叫做,这里面有一些我们写的代码,等一下我会举几个例子,我们写了一些函数,比如GetChar,意思是得到一个变量。
Well, for a thing called main which itself is a function but a function I wrote, a tool I am writing at the moment not like printf which someone else wrote long ago, I have to say where does main start, where does main end, and I do that by using these curly braces.
至于这个名曰main的函数,由我们自己写的函数,也是一个工具,只不过由我们自己编写,而不是像printf那样已经由前人写好了,我们必须要说明main在哪开始,在哪结束,这样我们就要用到大括号了。
应用推荐