Hello everyone my name is (name) and we are continuing with this C programming course in which we had discussed in the previous video, parts of functions in C programming.
We had seen that in which way our function gets divided into different parts in our program and what is the importance of each and every part in our program so that we can effectively use the functionality of the program in our program.
That is the reason we divide it into different parts.
So, in this video we start with functions and parameters.
So, we saw that there are different types of parameters as well which we will discuss ahead in this video about the types of parameters.
But before that the most important thing which is seeing a function practically and seeing how it practically works, all these things we will see in this particular video.
So, now let's quickly go to our text editor and there we will see how our function is looking.
So, this is our Visual Studio Code.
First of all, we will see this extremely basic function in which we are printing Hello learnvern.
This statement is very simple, you can say that this statement we can print with basic print F statement as well, what is so special about it.
The special thing about this is that we are implementing it with the help of a function.
We have made one function and with the help of that function, we are printing this statement.
We will see in which way it works.
And the first line that we are seeing.
We all know that it is called the preprocessor command and we are importing a S T D I O dot H file.
After preprocessor command.
Now comes the time of our function declaration, which we are writing in this way, you can see void out this is basically our function’s name, out.
You can see that I've commented and written here.
I've defined it as well.
We are calling it a function declaration.
We all know that the compiler starts reading the program from the start and starts executing the lines one after the other, so first of all the compiler will come and say that the first line is of a preprocessor command.
So, it executed it and imported the file.
Now he sees that what is the other line saying? So, the other line is saying that O U T which means an out named function, we will be using it in this program, which has a return type void which means for now it will not return anything.
So, this is basically a function declaration.
It is telling our compiler that a function named out we are using in this program.
So, the compiler got to know that okay there is a function named out whose definition is given below in the program.
So, whenever we will call this function, then we will go on its definition and execute its statement.
So, we have seen, suppose we are the compiler and we are reading the line one by one and we are understanding it one by one.
The first line we read of the processor command, the second line that we read was function declaration in which we got to know that OU T, out named function we are using in this program.
Now the time comes for our main function like we have discussed before.
Even before the main function, we tell our compiler which function we are going to use in our program.
That's why the function declaration part we have written on top of the main function.
So, after writing out , that is after declaring the function now, we are coming into the main function.
We will come into the main function and see that we have used one print F statement, what is it basically printing is H E L L O and there is one space as well.
So, it is printing Hello and space.
This much of the work was very easy.
It was very simple.
We understood it very easily.
Now we will go ahead and see in this main function, what is the second line saying.
In the second line it is written O U T round bracket and semicolon.
Now what does this mean? The O U T named function that we had made, we are calling it here because now there is a need for it in this program.
That is why we are calling it and this is called a function call.
So, you saw on the top that we had declared the O U T named function, so now you can see that there is no parameter given in the bracket. We had discussed it earlier also that in the bracket we have an option whether we want to give any input to the function or not.
In this particular case, since we are printing everything.
That's the reason why we don't need to give any inputs.
So, we will see how it gets printed.
That's why the parameter list portion is completely blank.
And that doesn't make a difference, when we need the input, we will take it and for that we will define our function definition early on.
But in this case, we didn't want any input or any parameter, that’s why we have left it blank.
So, we talked about function call.
Here we called the function named O U T.
So, here I need the function, inside this, which means the statements which were there, I want to get all those executed on that particular location.
So, the compiler said okay, as soon as the compiler encountered this O U T statement.
Where will it directly go? It will go to our function definition, with the function declaration we got to know that we will use the function of this name but as soon as the function call happened at that time, he got to know that okay, now is the time to go on the function definition.
And function definition we usually write below main or sometimes we even write on the top.
Here as soon as our compiler encounters the call function, he will go and search the function definition.
And where will he find it? After the main function you can see here that we have written one definition and we have written it like a syntax.
So, you can see that our compiler comes here on function definition.
And he reads v o i d, this is its return type after that we saw O U T.
okay O U T is also our function’s name.
We had earlier discussed its syntax. Since we didn't want any parameters, we kept the round bracket empty.
There is no compulsion to keep it empty.
Whenever you want the inputs or parameters, you can use it.
We will see in the coming programs how they can be written but, in this case, we didn't want it, so we didn't write it.
Now we will come into the body of the function.
Now what is written in the function’s body? There is one print F statement which is saying learnvern, so this learnvern statement is basically printing our out function.
So, what are the things that we saw? First of all, we saw a function declaration, so our compiler got to know that okay, so there is a function of this name in our program.
Then we saw a function call, where we needed the function, we had to print something, that's why we called the function.
As soon as the function was called, we went off, which means the compiler went off to the definition of the function and after going there he executed all the statements which were there in it.
So, you must be understanding the flow here of the function.
We will run it and see and then you will get to know in which way it works.
So first of all, as per us, the print F statement, which is saying “hello” space.
So, this should be printed.
After that, since we had called out function and the compiler had come here.
After that this Learnvern statement that we have written, should get printed.
So, we will quickly right click it, run the code and you can see that this statement got printed as it is exactly the way we wanted it to be.
So, first of all what got printed.
The print F statement got printed.
Hello and space after that we call the function and with the help of function call, we went on to the function definition.
And we saw that in function definition there is one more print F statement, which is printing learnvern.
When I encountered it, it was printed.
Behind these two there was no backslash N symbol.
Which would convert it in the next line.
So, in the same line, it has come and got printed.
So, hello space Learnvern.
So, it is saying Hello learnvern, so in this way our functions help us and make our program effective.
Since this was a simple program, you might say that we could have done this directly.
But when we see how things will get complicated, they will get complex.
At that time, who will help us? functions will help us.
So, we will see how in the next example how our function will help us, after that we will see this example.
What is this example doing? This is basically printing one number.
This is a basic functionality.
But how is it printing it, knowing that is more important.
In this situation or in this program.
We will also consider the parameters.
So, we will clearly understand how the parameters will work in our function.
Let's start with our preprocessor command.
We saw the S T D I O dot H file, we have imported that, after that you will see our function declaration.
What does the function declaration say? Number print function is in our program which has a return type void, V O I D.
And in that there will also be a parameter which data type would be I N T, which means integer.
So, this is a function declaration telling who, the compiler, now the compiler understood that number print function we will find further, we will encounter it.
And on its function call, we will have to go in function definition and we will have to execute the statements.
So, the compiler came into the main function and saw that the variable named num, which has 5 values has been initialised or assigned.
And what we did to num, basically assigned it and what we basically did to num, in the next step or the next statement, in the main function, we called the number print named function and in that parameter we put num, N U M variable.
In this way while making the function call, we write variables and parameters.
If there is more than one, we separate it by commas and go on writing it ahead.
So this is how our function is called.
As soon as our compiler knows that the number print has been called, it will go on to our function definition.
Which is written here below.
So, we have come to function definition, you can see that void written type here, after that number print is our function name.
The important thing here is I N T A.
This parameter which is written we will discuss about it. Now what happens basically if we see in our main function we have made a variable named N U M and we have assigned five values in it.
So, what had happened in it, in the N U M variable, 5 values have come.
And we have put that num variable in our number print function.
So, in this situation, N U M was our actual value.
So, that is the reason why we call it the actual parameter.
So, you can see here that while calling the function the function’s name is N U M and in the function definition the variable’s name is different.
So, why is that that we will understand? So, num was our actual parameter.
Which means it is the actual thing, on which we have to do the processing that happens on the function.
So, we will call it the actual parameter.
But, A variable which is written in our function definition.
We call it a formal parameter.
You can even see in the comments on the side.
We call A, a formal parameter.
Why do we call it that? A is basically the formal part of the parameter.
What do we usually do ? Here only once we call the number print function.
Sometimes what happens is we have to call our function more than once.
And it is not necessary that every time we will call with that particular variable.
What we can do here is we will make one more variable.
Like we made num 1 and I have given it value 6 and I have given it a semicolon.
And after that one more time… we will remove it for once.
So, what will I do here? I will make one more function call.
This time what I will do is I will put the num 1 variable inside it.
So, in this way we can combine different variables with the same function, we can club it and call it.
So, it is not necessary that the variable’s name be written in the function definition, that and the variable’s name written inside our function call, should be the same.
This is not necessary because with different variables we have to call the same function that is the reason why we keep them separate.
So, whenever we write the variable in a function call, we call it actual parameter because actually on that thing we have to perform the operation, considering that thing we have to run our function but whatever is in the function definition, basically the variable.
You can see here that the name of that particular variable is A, we call it a formal parameter.
Why? Because you change any variable here write, num, num 1 or if we make num 2, we will write num 2 as well.
But where will that num 2 come basically? This number print’s definition, it will absorb with this A.
Because both their data types will remain as integers.
This is fixed that at the time of function call it is integer.
And in function definition it will be float, this is not possible.
Both of their data types would be the same but variable names will differ.
Because sometimes what happens is that as per you let's take an example in our family, my parents will call me son but my friends will call me by my name.
So, in this way in different places, we call one thing with different names, in the same way in function definition we're considering that particular variable with the name A or addressing it and in function call we are addressing it with variable names.
So, we must understand this much that the parameters that we will write at the time of function call, we will call them actual parameters.
Because they are actual and in function definition, the parameter that we will write.
Those we will call as formal parameters because they are local for that particular function, which means that they'll be valid till that function.
A variable, I will not be able to use it here.
A will remain inside this.
So, in this way our parameters work and we just see that in function definition we will get the variable printed.
But what will be printed, it will print from here, the value that was taken from num.
So even that will be basically printed here.
So, we will run this once and see what gets printed.
I will click on the run code.
I will do one thing.
I will also give a space here.
With the space, both the values will get segregated.
I will click on Run.
And you can see that here five also has got printed and six also has got printed.
So, we can see here that I called the function twice with different values.
But here locally inside the function definition, we only called A, in a num value also comes and in the second time num 1 value also comes.
So here we address it with a and we get a printed but which value gets printed, 5 which means num and 6, of num 1.
So, in this way our parameter works.
Now there are 2 more ways to call this parameter.
Apart from these we will see them in the coming videos.
So, for now, we will understand what is an actual parameter? And what is a formal parameter, we can segregate these two very easily.
At the time of function call will be an actual parameter and at the time function definition it will be a formal parameter.
So, in this way the story of the parameters will go on.
In the coming videos we will see in which ways we can call the parameters.
Here you saw a way, simply one value which was a num value came into A and we executed it.
There are other ways apart from these.
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
In the coming video we will see, what we call as call by reference or call by value.
So, for now, we will only remember actual parameters and former parameters.
Till that time, we will meet in the next video.
You keep on practising.
Thank you so much.
Share a personalized message with your friends.