Function Definition in C

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this presentation we will talk about the function definition in C so let's get started what is function definition function definition consists of block of code which is capable of performing some specific task like for example here is the block of code which can perform the addition between two numbers available inside these two variables a and B right so this is a function definition here is the function and here is the block of code which can perform some specific task therefore this is the function definition right after understanding this function definition now let's try to understand how function works here you can see I have written a prototype of the function add you should not forget to mention this prototype of the function as we know I have not written the definition before calling the function therefore I should mention the prototype of the function over here recall that there is no need to mention the names of the parameters here you should not mention the names of the parameters you should only mention the data types of the parameters as well as the return type of the function this is the way we should write down the function prototype after that we have a main function and inside this main function we have three variables M n n some M contains value 20 and contains value 30 and some will not contain any value whatever will be the result will get stored inside this variable after that in the next line we have some equals to add M comma n let's try to understand this piece of code this is the way you call a function note while calling a function you should not mention the return type of the function also you should not mention the data types of the arguments here you should not mention the return type and you should also not mention the data types of the arguments you should only mention the names of the arguments this is very important to note on when you are calling a function now as we know when we are calling a function the control will get transferred from this position to this position that is the actual definition of the function this is the way you define a function right here you should remember it is important to mention both data type and name of parameters that means you should mention the data type of the function as well as the names of the parameters that means in the function definition you should mention everything you can easily spot the differences between the function definition the function declaration as well as when we are calling the function now as I'm creating two different variables a and B over here in this function therefore I should mention them over here variable a and variable B these are the two new variables created by this particular function now as we know when we are calling the function we are passing the values of m and n to these variables a and B value of M which is 20 will get passed to this variable a and the value of n which is equals to 30 will get passed to this variable P therefore a will now contain value 20 and B will contain value 30 now inside this function we are manipulating these values that means we are adding these values right this variable a will get replaced by 20 and this will get replaced by Totti and then finally we add them together which will return 50 finally we simply return this value 50 back to this calling procedure right this is how the flow works and the function will get replaced by 50 now some variable will contain value 50 and after that we simply print sum is 50 right this is just a placeholder and this placeholder will get replaced by this value 50 so sum is 50 will get printed on the screen right this is the way how function works now let's execute this code in order to know whether it works exactly as what we want here is the piece of code and this is exactly what we have seen in our presentation so let's execute this code to see the output yes some is 50 because these are the two values 20 and 30 some of these two values is 50 therefore some is 50 will get printed on the screen so this code works fine now let's get back to our presentation now let's try to understand what is the difference between an argument and a parameter we are using these terms interchangeably in our code and I will use these terms later therefore it is important to understand the difference between an argument and a parameter let's see what they are parameter is a variable in the Declaration and definition of the function and argument is the actual value of the parameter that gets passed to the function and please note down that parameter is also called as formal parameter an argument is also called as actual parameter let's see the example to better understand what is the difference between parameter and an argument here is the example which we have already seen these two variables are called as your arguments or actual parameters and these two variables are called as parameters or formal parameters so basically these are the formal parameters and these are the actual parameters so when we are calling the function variables available in the calling function are called as arguments and the variables in the definition or the Declaration of the function are called as the parameters please remember this point okay friends this is it for now thank you for watching this presentation [Applause] [Music]
Info
Channel: Neso Academy
Views: 187,425
Rating: 4.9382424 out of 5
Keywords: function definition, function definition in c, function definition and declaration in c, definition of function, definition of functions in C, working of function in c, function example in c, example of function in c language, difference between argument and parameter, c programming, c programming lectures, c programming functions, c programming for gate, gate c programming, c programming for interview, functions in c
Id: gF7wjwM9Jjs
Channel Id: undefined
Length: 6min 3sec (363 seconds)
Published: Sat Oct 06 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.