Hello everyone, my name is (name) and we are continuing this C programming course in which we had discussed in the previous video functions used in C programming.
We had seen what exactly is the function and after that we saw which are the parts of the function, which we have to use in our program to make one function effective.
Going ahead, we saw there are a few parts of the functions which we have to always use to make use of the function in our program.
We saw that there are these three parts.
First part was function definition.
The second part that we discussed was function call and third which we discussed was function declaration.
We will see syntax to all these things in this particular video.
So, this video is going to be about those function’s part, the function definition, the function call or the function declaration.
What will be the syntax of all these things, what will be the way of writing it and how effective it would be.
We would discuss all these things in this video.
We will go on to the first part which is called function definition.
And we will see how it is written, and what its syntax is.
So, you can see on the screen the syntax of the function definition in which you're seeing one in indifferent colour, return type, then comes function name and in the third round bracket you have been given a parameter list.
And after that in the curly brackets we all know is the body of the function.
So, we will see basically what these things are one by one.
First of all we will see what the return type is basically.
So, here we are talking about components of function definition.
From this the first component is visible on the screen, which is the return type.
We had discussed what function is? It is a set of statements which will take some input, after taking the input, after doing some calculation on it after processing.
It will provide some output.
The type of the output, which means the output which will be in the form of some variable, inside which some value will be stored.
The variable will be of what data type? Will it be integer, float or will it be string.
So, how will we get to know all these things?
We will get to know from the function’s return type, which means the output that we are giving, the value that we are returning from our function, what would be its type.
Which means, what would be the data type of that particular variable that we will get to know from the return type.
What does its definition say? “It is the data type of the value which the function will return.
If the function does not return any value, the data type will be void”.
We had seen that if any variable doesn't have any particular data type, which means there is no value stored in it.
The data type by default becomes void, in this case also if our function is not giving any value in output, which means it is not returning then its data type would also be void.
So here we discussed what the return type is doing in this particular syntax.
Going ahead we will see what the function name is.
So, now we are making the functions, we are defining the function, one particular function, for example we made a function named S U M, sum and what is that sum doing? Any values stored in the variables, it is adding them and giving it to us.
So, the functionality of sum, we had to give it a name.
which we called S U M.
So, in the same way we have to name the different functions only then we will get to know that this function is being used here.
Its name is different so it has been used here.
In this way we will have to give names every time to everything.
So, we have to name this and we call it function name.
So, it is the name given to the function by the programmer as per our wish as long as it is coming in the rules of the identifier.
So, here we have seen the return type and function name.
Now we are going ahead and seeing the parameter list.
So, what is this parameter list? “This list refers to type, order and number of parameters of the function.
A function can have no parameters also”.
Here this is its definition but what will exactly come in this parameter list.
So, we have discussed that the function basically takes some input which it processes and after the processing it gives some output that's why from where the input is taken, we call it parameter list and the round bracket that you're seeing in this we have to write our inputs.
Now these inputs are in which form? These are generally in variable form, along with that particular variable, we also have to write its data type.
Since we have to write the data type, we have read it in the definition as well.
This particular list refers to type, type means the data type and order.
Order means which are the inputs that we are taking, we're taking five inputs together.
So, we will put it in such order first, then comma then second input, then comma then third input all these things we will write in one order.
Here we also get to know how many parameters, how many inputs we are giving to our function.
So, this parameter list is the list where we will be writing our variables which are the input variables with their data types.
Which means with the data types, even their names will be written and their values would be already stored in it.
So, there is no need to write the values.
Like when making the normal data types we write variables and their names in the same way how many variables we have to put in parameter lists, in which there will be some value which we are putting the input of.
Along with the data type we have to write the names of the particular variable.
So, to the particular variable, along with the names we will have to write the names in our parameter list.
Till here we have seen return type, function name and parameter list, after that we are seeing the body of the function.
We all know that like we had seen the body inside the loop or inside the if, in the same way inside the curly brackets there are a set of statements, these are the main set of statements which are doing the processing part.
We have taken the input in the function but who will work on it? Statements will work on it, like we have to make an additional function with the name of S U M.
It is an additional function.
So, what is the functionality that we have to put in it? What is the statement that we have to write? We have written two variables, in the input that is in the parameter limit list A and B.
But after coming inside the body of the function, we will have to define A plus B is equal to, we have to store it in C.
The C will go and print in the output and the same way a+b=c the statement that we'll be writing, the statements which will process our input and provide the output, all these things will come in the body of the function and these four things that we saw, return type, function name, parameter list and body of the function, all these things are basically the part of our function definition.
When we will be using it practically in our text editor, then we'll understand it better.
But for now, let's understand when we talk about the function definition in which we were talking about everything about the function we write in that particular definition.
In the same way, you have seen here that what will be the data type of the output, even that we have seen, the function will be known by which name even that we have seen and we have seen that even the input data type will be written, which all variables were taking in input, even that we have written after that we also define the body of the function, which means which are statements we will be putting in our function, all these things we have defined under function definition.
So, we have seen the first part of our function which was function definition.
Now we will go ahead and discuss function declaration, this function definition that we have seen till now.
What is it? Anywhere at the start or at the end of the program we write it, right?
We used to discuss the main functions every time.
These are the main functions, which means this is the main door of our program, in which basically our main program starts, so the main function which is there, outside of that we would have to write the function definitions.
What was the definition? In which we basically write the statement about the function.
we will write the definition either on the top of our program or on the top of it or after the main function.
If we are writing our function definition after our main function then we will have to tell the compiler before starting the program that we are using this type of function in our program.
To tell that, we are using the function declaration statement.
So, it tells the compiler about the function name and how to call the function.
I've told you that below the main function we have written the function definition and written all the information about the function but that is at the end and we know that in the main function our main program is there.
So, our compiler will always execute the main function and then it will reach the bottom to the function definition.
Until that time, we will not understand that this particular name function existed, I had not seen it.
These things shouldn't happen.
That's why before the main function we write the function declaration, before the main function.
So that our compiler knows that this particular name function is there and below its definition is written.
Whenever we have to use it in our program.
Our compiler will know that its definition it has seen below, it is written down.
So, he will come below the definition and he will do what all processes that need to be done. -10:46
This is basically the part of function declaration.
We will see quickly how the syntax of the declaration will be written.
This is similar to definition but in this only the body of the function is not there.
There are no statements basically, if it was a statement, it would have become a definition.
So, you will see that it return type exactly like the definition.
There is a function name as well.
And there is even a parameter list but there is no body of the function in it.
That's why you can say that this is function declaration and function declaration is always above the main function, it's on the top in the program, so that the compiler knows that there is a function of this name but if I say that I don't have to do this, what I have to do is I have to write the function declaration on the top directly.
Then will I need the function declaration? It won’t be needed that time.
Why? Because my compiler will get to know before reaching the main function that the function’s name is this and this is its definition.
This process of writing the function declaration, we will skip this and directly write the function definition on the top of the main function.
So, there is no need to write the function declaration.
I have told you what is the need of writing the function declaration.
This is needed when our compiler doesn't know that this name function definition is there.
Why? Because we have written below the main function, all these things are useful when our program becomes big.
At that time, it is more useful.
Because at that time we don't understand where we must have written the function definition, below or on the top.
When all the function declarations are written on the top, we get to know which functions we are using, so its definition would be just below the main function.
So, we have seen what exactly is function declaration.
“only type is required in function declaration, we can skip the parameter name as well”.
There is one more special thing while writing the statement of function declaration like we had discussed in the parameter list, we have to get data type of the variable as well as the name of the variable, both of these things should be written in our parameter list.
But when we talk about the declaration, in declaration if we only write the data type, if we don't write the variable’s name even then it is allowed because there are no errors or problems in it.
Because basically our function is only concerned with the particular input that we are taking, that input will be of which type, will it be integer, float or in the string.
Our compiler should only know which type of input we are taking inside.
If we don't name it that's okay.
That’s why in function declaration, if we skip the name of the variable, that is fine.
But writing its data type is very important.
I have told you early on that if we write function definition on the top of main function, then there is no need to write the function declaration.
We can safely skip that.
This was about the function definition as well as function declaration.
Now we will quickly see what function call is.
“To use a function, we have to call that function to perform the given task”.
So, this is our function cost of which we just read the definition.
Till now we have understood what is function definition, where we have written all the information about the functions and after that what is function declaration?
That statement which tells our compiler that this name function we are using in our program.
What is this function call? Like we have seen in the example of any person, if he's asking me my address, he is asking me for my address.
That time it is called function call.
Which means he is asking me to give my address.
This we call as function call, whenever in the main function, we will have that function's requirement.
Like I have given you an example, we have made this sum named function which has the work of adding two numbers and giving the output, whenever in the programme I have to perform the addition of two numbers.
I have to sum it up, what I will do is I will call this particular function in my program, inside.
With this the compiler will understand the definition and the compiler will straight away come to the definition and see that this function wants to do all these things.
Whatever things that the user has written in the program, he will take it as an input in function definition, and he will execute the statement and process it, complete it and whichever output it provides, that output will again go into the program, as an output in the variable, it will store any value and give it.
So, all these things should not get very complex.
Hence, for now we will understand that we have written a function definition somewhere in the program and we have to use it, how will we use it? We will use it through a function call, which we will see how it is written going ahead.
“When a program calls a function, the compiler gets redirected towards the function definition”.
So, this is the thing which I told you right now.
When we have to use the function.
What we will do is, make use of function call and as soon as our compiler will see this function called statement, it will directly go to our function definition and it will see what all is written in the definition, then it will execute the output and provide it.
“Function call simply pass the required parameters along with the function name.”
So how is function call written? We know that in function we have to give the input.
So first we have to say what is the name of the function, which is the function which you are using because in one program, we can use more than one function.
So, we have to write the functions name and along with that inside the round brackets, we also have to give the parameters, which means what are the inputs that we will give to our function even if we have to write.
So all these things we have discussed about the function call.
We will see these in our practical, in which way when we are making functions in our text editors, what will be the definition part, what will be the declaration part or in which way it can be called.
All these things we will see properly when we will go into our text editor and understand it.
We had seen about parameters.
We will discuss again, what exactly are these parameters.
Here you are seeing one example.
I have written one function, what will be its return type?
Its return type is I N T, which means integer.
Because we know that the first thing that is written while making a function is the return type and here you can see that the return type is I N T.
I N T means integer.
Whatever my function will calculate, all the value output it will give, the value that will come, what will be its data type? Its data type will be integer.
In the same way here my function’s name is max, M A X.
After that I have given round brackets, in which I'm writing my parameters.
So here what I have to do, for example, let's understand one more thing again.
What I have to do is, in between two numbers I have to find out which one is the larger? Which means which is the maximum number from both.
Like I have taken 2 and 1.
So, what will this function do? It will consider 2 and 1 and check whether 2 is greater than 1 or 1 is greater than 2.
In this way the functionality will be done by this particular function, we have named this M A X, max, means it will tell between the two numbers, which is the maximum value.
So, we have to give two numbers as input.
Those numbers are num1 and num2.
So, I have given the name of these two variables whose data type also I have written along with it, which is I N T, which means integer.
So, any two integer values will be taken as input by my function.
And it will do a comparison between the two.
Whether 2 is greater or 1, which one is greater in both.
Whichever is the big one it will return that particular value means it will provide as an output, you can see here that output will be in the integer format.
Whichever value we will be providing in the output.
That value will remain as an integer.
In this way our function parameters work.
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 next video, the things that we will be discussing, those would be our types of parameters.
There would be these two types, call by reference and call by values.
Till the time don't make it more confusing and complex.
Just understand that in the coming videos, we would be seeing how many types of parameters are there and how they will be considered in our function.
Until that time, we will practice this and we will meet in the coming video.
Thank you so much.
Very happy 😄😁
Very happy and greatful, thank you , great course.
Super for poor students to learn software course languages TQ