Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,240 --> 00:00:01,420
What is going on, guys?
2
00:00:01,440 --> 00:00:08,220
I hope you are doing well and I hope you've successfully passed the previous introduction to functions.
3
00:00:08,880 --> 00:00:13,560
This will definitely make your learning process much easier from now on.
4
00:00:13,680 --> 00:00:19,540
So now let's get to work and talk about functions now or C programming language.
5
00:00:19,680 --> 00:00:27,180
And first of all, what I want to talk about here in this section is that every function has its signature.
6
00:00:27,540 --> 00:00:29,340
So we'll will say that signatures.
7
00:00:29,370 --> 00:00:31,530
Correct arises the function.
8
00:00:31,560 --> 00:00:31,800
OK.
9
00:00:31,860 --> 00:00:33,350
So a signature correct.
10
00:00:33,350 --> 00:00:34,500
Arises the function.
11
00:00:34,650 --> 00:00:37,410
It simply describes the functions name.
12
00:00:37,500 --> 00:00:38,000
OK.
13
00:00:38,130 --> 00:00:42,590
And it also describes the functions expected parameters list.
14
00:00:42,630 --> 00:00:43,880
We will talk about it.
15
00:00:44,160 --> 00:00:45,210
We will talk about that.
16
00:00:45,690 --> 00:00:51,560
And we also said that we can expect that the function may return something.
17
00:00:51,590 --> 00:00:56,030
So basically the signature will also specify this one.
18
00:00:56,040 --> 00:00:59,820
What will be the returned type of any given function?
19
00:00:59,970 --> 00:01:04,950
It will simply say what type of data the function is expect.
20
00:01:05,040 --> 00:01:10,410
And and it's going to return in its template to looks basically like this.
21
00:01:10,590 --> 00:01:13,080
First, we specify the return type.
22
00:01:13,620 --> 00:01:16,040
Then we specify the functions name.
23
00:01:16,620 --> 00:01:22,800
And lastly, we specify what are the expected parameters that the function should get.
24
00:01:23,070 --> 00:01:24,690
Once it's called.
25
00:01:24,840 --> 00:01:28,730
So this structure or first of all, the return type.
26
00:01:28,770 --> 00:01:29,970
Then the function name.
27
00:01:29,970 --> 00:01:31,440
And then the parameters list.
28
00:01:31,680 --> 00:01:36,540
It's called a signature in our C programming language.
29
00:01:36,660 --> 00:01:41,040
That that's how we characterize a function.
30
00:01:41,100 --> 00:01:41,520
OK.
31
00:01:41,670 --> 00:01:46,320
And the main three things to note here are what type of data?
32
00:01:46,350 --> 00:01:48,120
The function is going to return.
33
00:01:48,150 --> 00:01:48,450
OK.
34
00:01:48,750 --> 00:01:51,660
So we know that we may have different types of data.
35
00:01:51,690 --> 00:01:52,050
Right.
36
00:01:52,350 --> 00:01:53,550
We have integers.
37
00:01:53,580 --> 00:01:57,510
We have floating points, characters, strings and so on.
38
00:01:57,690 --> 00:02:02,850
And what we would like to do is to specify before we are even using any function.
39
00:02:03,120 --> 00:02:07,800
What will be the type of data that the function is going to return?
40
00:02:08,040 --> 00:02:13,020
So, for example, the return type can be into double char and so on.
41
00:02:13,200 --> 00:02:13,460
OK.
42
00:02:13,650 --> 00:02:19,020
Simply specify the type of data that these function is about to return.
43
00:02:19,350 --> 00:02:24,960
Just like with the explanation we had in the previous videos where we said that we may think of every
44
00:02:24,960 --> 00:02:28,200
function as some guy with some profession.
45
00:02:28,350 --> 00:02:34,170
And for these guy, the return type basically means what will you expect to receive?
46
00:02:34,590 --> 00:02:36,750
What what should you receive?
47
00:02:37,020 --> 00:02:38,130
Once the guy.
48
00:02:39,230 --> 00:02:44,300
Of these guy, these functions, these join in this example will finish his execution.
49
00:02:44,300 --> 00:02:49,800
And what what will what we expect to get in return once it's done.
50
00:02:49,900 --> 00:02:50,160
OK.
51
00:02:50,370 --> 00:02:53,340
And there is also something new to mention here.
52
00:02:53,710 --> 00:02:59,590
There may be functions that will not return anything, anything at all, and that's OK.
53
00:02:59,970 --> 00:03:05,550
So in this case, instead of using into double or char as part of the signature.
54
00:03:05,820 --> 00:03:09,300
When we wanted to return some type or some value.
55
00:03:09,330 --> 00:03:12,270
OK, we are going to use void.
56
00:03:12,390 --> 00:03:14,240
And that's how it looks like, OK.
57
00:03:14,310 --> 00:03:21,210
So Void specifies that we do not expect that a function will return anything.
58
00:03:21,240 --> 00:03:21,390
Okay.
59
00:03:21,510 --> 00:03:27,060
We can just call it, for example, a function that all it does is simply to print some information
60
00:03:27,060 --> 00:03:28,560
to the screen to display something.
61
00:03:28,920 --> 00:03:34,050
We don't expect to receive something in return from this function.
62
00:03:34,080 --> 00:03:34,380
OK.
63
00:03:34,590 --> 00:03:38,220
And I've just notice that I'm saying a lot of times in this video, the world.
64
00:03:38,350 --> 00:03:40,620
OK, so let's stop it.
65
00:03:40,770 --> 00:03:41,370
OK.
66
00:03:41,550 --> 00:03:44,070
And if we come back to talk about the functions.
67
00:03:44,130 --> 00:03:50,020
So one function, John, will return an integer and Mary will return nothing.
68
00:03:50,060 --> 00:03:50,940
And that's all.
69
00:03:51,060 --> 00:03:51,500
Also.
70
00:03:51,500 --> 00:03:51,910
OK.
71
00:03:52,560 --> 00:03:57,510
So now let's talk about the functions name, which is simply the name of the function.
72
00:03:57,510 --> 00:03:59,130
You remember John, don't you?
73
00:03:59,550 --> 00:04:05,790
And we should give every function in name so that we will be able to distinguish between different functions.
74
00:04:05,880 --> 00:04:07,790
When we are going to call them.
75
00:04:07,950 --> 00:04:14,070
So the function name is very similar to a variable name and you can name or function however you like.
76
00:04:14,220 --> 00:04:19,270
Just don't use any reserved words or something that we can not using, see.
77
00:04:19,280 --> 00:04:19,600
OK.
78
00:04:19,860 --> 00:04:21,110
And once again, this OK.
79
00:04:21,270 --> 00:04:25,710
And my suggestion for you guys might tip for you when you're using functions.
80
00:04:26,730 --> 00:04:29,460
Never get lazy about naming your functions.
81
00:04:29,490 --> 00:04:34,470
And always try to give your functions such a name that will describe its purpose.
82
00:04:34,710 --> 00:04:42,390
What it does in the best possible way, because you see, as you keep on moving forward and developing
83
00:04:42,390 --> 00:04:45,990
much greater programs, you are going to have a lot of functions.
84
00:04:46,380 --> 00:04:48,630
And even the naming of them was bad.
85
00:04:48,840 --> 00:04:54,750
Then you're probably going to experience a lot of difficulties in managing your code and all of your
86
00:04:54,750 --> 00:04:59,760
program is going to become one big mess that you will be the.
87
00:05:00,000 --> 00:05:03,790
You won't be able live in two to be capable of reading.
88
00:05:04,140 --> 00:05:07,320
And I'm not even talking about further development.
89
00:05:07,920 --> 00:05:14,760
So if the function calculates the average of something, make sure that the name will represent at least
90
00:05:14,880 --> 00:05:20,610
the fact related to the average or if the function is responsible for the like button.
91
00:05:20,640 --> 00:05:23,790
Let's see that is being used on some social media.
92
00:05:24,180 --> 00:05:30,450
Make sure that once you read the functions name, you already understand, at least to some extent,
93
00:05:30,750 --> 00:05:32,970
what this function does.
94
00:05:33,090 --> 00:05:39,350
So, for example, in our previous sections we've written some code that prints out the minimum and
95
00:05:39,360 --> 00:05:42,240
the maximum between given two numbers.
96
00:05:42,480 --> 00:05:46,370
So the function name may be at least print mean marks.
97
00:05:46,410 --> 00:05:46,630
OK.
98
00:05:46,770 --> 00:05:53,250
It says what these function will do, it will print and perhaps it will print minimum and maximum.
99
00:05:53,490 --> 00:06:00,720
Or maybe if we have some other function that calculates the average grade than in this case, we will
100
00:06:00,720 --> 00:06:03,450
call this function find average grade.
101
00:06:03,600 --> 00:06:03,850
OK.
102
00:06:04,080 --> 00:06:10,590
So we see the name of the function and we understand what these function mainly does.
103
00:06:10,620 --> 00:06:10,920
OK.
104
00:06:10,980 --> 00:06:17,610
So the general concept of the function, we can guess just by reading its name and that's very important.
105
00:06:17,730 --> 00:06:23,280
And so lastly, we have also the functions expected parameters list.
106
00:06:23,520 --> 00:06:23,870
OK.
107
00:06:24,300 --> 00:06:27,870
You remember that a function is just like someone with a profession.
108
00:06:27,900 --> 00:06:31,560
And whenever you call him to do something, you pass him.
109
00:06:31,830 --> 00:06:33,780
You give him a couple of things.
110
00:06:33,900 --> 00:06:37,920
So, for example, if you're using a painter that paints your house.
111
00:06:37,980 --> 00:06:46,560
There may be some parameters that we would like to give these painter before are he or she starts his
112
00:06:46,560 --> 00:06:47,410
or her work.
113
00:06:47,490 --> 00:06:47,880
OK.
114
00:06:48,090 --> 00:06:48,900
Like the color.
115
00:06:48,900 --> 00:06:54,660
We want to use your address where you live and how much money can you offer.
116
00:06:54,750 --> 00:07:01,860
So I hope that's clear for him, for this example, of what parameters a painter may may want.
117
00:07:01,890 --> 00:07:02,130
OK.
118
00:07:02,260 --> 00:07:05,220
So a color address, money and so on.
119
00:07:05,850 --> 00:07:12,290
Or if there is another example, let's talk about another example where we have a function to print
120
00:07:12,360 --> 00:07:14,350
the minimum and the maximum.
121
00:07:14,370 --> 00:07:15,900
Between two numbers.
122
00:07:16,260 --> 00:07:21,030
Then the function in this case definitely should receive two number assess parameters.
123
00:07:21,090 --> 00:07:22,170
So number one.
124
00:07:22,260 --> 00:07:23,220
And number two.
125
00:07:23,370 --> 00:07:30,060
And basically, once it's receives the numbers, it will print the meaning moment, the maximum between
126
00:07:30,360 --> 00:07:32,940
these two, number one and number two.
127
00:07:33,030 --> 00:07:40,020
So to summarize it, every function may include multiple parameters that it will expect to receive once
128
00:07:40,080 --> 00:07:41,370
somebody calls it.
129
00:07:41,820 --> 00:07:46,760
And this list may also be empty, meaning no parameters at all.
130
00:07:46,770 --> 00:07:47,740
And that's OK.
131
00:07:47,790 --> 00:07:49,070
It's not mandatory.
132
00:07:49,080 --> 00:07:55,350
We may pass a couple of parameters and we may also do not send anything.
133
00:07:55,800 --> 00:07:56,550
That's fine.
134
00:07:56,730 --> 00:08:02,090
A function does not necessarily should have a list of parameters, but it may have it.
135
00:08:02,190 --> 00:08:08,310
So now once we're done with all the formality, we are going to take a look at four exercises that each
136
00:08:08,310 --> 00:08:11,730
of them is going to use some different type of functions.
137
00:08:11,970 --> 00:08:14,010
In terms of a return type.
138
00:08:14,490 --> 00:08:16,830
And as well as a name, of course.
139
00:08:16,890 --> 00:08:19,740
And every function he's going to use at different.
140
00:08:19,770 --> 00:08:22,860
Let's call it a different set of parameters list.
141
00:08:22,890 --> 00:08:30,000
I want you to to see are all, let's say, the standard options for functions that we can have.
142
00:08:30,060 --> 00:08:34,080
So basically there are going to be four examples and function.
143
00:08:34,080 --> 00:08:40,710
No one will be with no parameters and nothing in that it will return.
144
00:08:40,710 --> 00:08:43,080
So would be will be of a void type.
145
00:08:43,200 --> 00:08:47,910
And this function, all it's going to do is simply to print a greeting message to the screen.
146
00:08:48,390 --> 00:08:53,390
So we are going to develop this as our first exercise.
147
00:08:53,580 --> 00:08:57,960
Then we are going to take a look at the second function and function number two.
148
00:08:58,230 --> 00:09:00,270
That will contain some parameters.
149
00:09:00,360 --> 00:09:02,610
But it will return nothing.
150
00:09:02,630 --> 00:09:05,220
So it still will be of a void type.
151
00:09:05,380 --> 00:09:10,740
And what we are going to do in this function, in these second function, is that we are going to receive
152
00:09:10,740 --> 00:09:11,640
two numbers.
153
00:09:11,670 --> 00:09:12,900
Number one and number two.
154
00:09:13,260 --> 00:09:17,550
And then print the maximum and the minimum between them to the screen.
155
00:09:18,060 --> 00:09:20,310
But it will not return anything.
156
00:09:20,340 --> 00:09:20,580
OK.
157
00:09:20,640 --> 00:09:22,920
Please note that there is a difference.
158
00:09:22,950 --> 00:09:30,180
It's very important difference that you must understand between returning something which is an internal
159
00:09:30,180 --> 00:09:36,570
functionality between functions and printing to the screen, which is a totally something different.
160
00:09:36,620 --> 00:09:36,990
OK.
161
00:09:37,350 --> 00:09:40,710
It simply displays some text on the screen.
162
00:09:41,100 --> 00:09:43,290
So make sure you understand the difference.
163
00:09:43,320 --> 00:09:46,620
Because it's crucial for our future sections.
164
00:09:46,770 --> 00:09:53,420
And once we are done with function number two, we are going to proceed to function number three, where
165
00:09:53,430 --> 00:09:57,660
we are going to have no parameters at Oles at all.
166
00:09:57,960 --> 00:09:59,730
But we will ex.
167
00:09:59,830 --> 00:10:03,550
React to, first of all, receive something in return.
168
00:10:03,610 --> 00:10:05,660
Once we called these function.
169
00:10:05,820 --> 00:10:11,800
So we are going to write a function that gets nothing is a parameter, but reads from the user three
170
00:10:11,800 --> 00:10:16,540
numbers, which are going to be local only to this particular function.
171
00:10:16,540 --> 00:10:16,890
Right.
172
00:10:16,990 --> 00:10:26,020
And then the function is going to find out and return the maximum value between these three variables
173
00:10:26,290 --> 00:10:28,660
or values that we read from the user.
174
00:10:29,320 --> 00:10:35,350
And lastly, we are going to take a look at function number four, which has some parameters.
175
00:10:36,040 --> 00:10:39,970
And also, we expect that it will return us something.
176
00:10:40,120 --> 00:10:43,210
So this function is going to receive three grades.
177
00:10:43,300 --> 00:10:43,680
Okay.
178
00:10:43,750 --> 00:10:50,470
It's going to receive your three grades, calculate and find out the average grade and then return it
179
00:10:50,530 --> 00:10:52,120
to whoever called it.
180
00:10:52,240 --> 00:10:58,690
So as you can see, there is a lot of content, a lot of information that we are going to study and
181
00:10:58,690 --> 00:11:01,990
to learn in these our exercises.
182
00:11:02,020 --> 00:11:05,080
And this of variance of functions.
183
00:11:05,230 --> 00:11:11,920
And hopefully, once we practice this topic a little bit together, you will be able to proceed to other
184
00:11:11,920 --> 00:11:13,210
challenges on your own.
185
00:11:13,810 --> 00:11:20,050
That's our main goal, to make you prepared for handling things and writing functions on your own.
186
00:11:20,950 --> 00:11:26,230
So, guys, with that being said, let's move on to solving our examples.
187
00:11:26,440 --> 00:11:27,280
I'll see you there.
16885
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.