 Hello friends, I am Sanjay Bhukta. I welcome you on Sanjay Bhukta Tech School. In this video, I am going to explain one of the important topics that is callback value and callback address of C language. So after watching this video, you will get to know how these two things works in C language. So first I am going to explain callback value. So I am taking example of swapping. So I am declaring a function. So here you can see written type of function is void. Its name is swap. And it will be having two inputs as integer type for processing. After this, I am defining main function. So first we are going to understand this callback value. So here I have two variables a and b. A is 5 and b is 10. Now I am going to print their values. So first this message will be printed before swap then a equals to percent b comma b equals to percent b and then a comma b their values. Then I am going to call the function swap and I am going to pass values of a and b. So this is the calling statement. This is the calling statement. And from here we are passing values of a and b. That's why it is known as callback value. And after this I am writing printf and after swap equals to percent b equals to percent b and a comma b. And then I am closing this. So this is the main function definition where I am going to call swap function. And after completion of main function definition now I have to define swap function definition. So I am writing that so void swap int x int y and a temporary variable z. So here I am going to apply the logic for swapping. I hope you know this swapping logic already. So this is some simple swapping logic that will change values which are available into x and y variable. So now let's understand how all the value works. So when we execute this program so a and b will be never done and this output will be printed before swap a and b. So output will be before swap it will print a 5 and b 10. So this output will be printed with the help of this printer. Now the calling statement will transfer control to its definition. So here we can see we are passing a and b values. So that's why this is called the value. So value of a will be passed to x value of b will be passed to y. So in main function a and b will be having separate memory block along with values when a and b is when a and b are passed to x and y. So x and y will be having their separate memory because they are declared with int data type. So x will be having 5, y will be having 10 because these two variables are passed as input to b. So I hope you understood a and b having their separate memory and x and y having their separate memory. Now we are performing strapping operation on x and y. So x will be 10 and y will be 5. So now if I am changing value of x so value of a will change or not? No. Because there is no relation between a and x and b and y. So x is having its separate memory location. So it is changing its own value. Y is having its own memory. So it is changing its own value. So if we change x, so no change will be done on a. If we change y, no change will be done on b. So after completion of this function definition, we need to print this print f. So it will print after swap a is 5 and b is still 10. So no change on a and b variables because x and y are copies of a and b. And there is no relation between a, b and x and y. So this is the limitation of call by value. So you can remember one thing. If we change variable values in function definition, so no change will be done on the caller of the function. So caller is main. Main is calling the swap function and swap is doing a change in its variable. So no change will be done on the variable which are applicable inside main, right? Now after understanding call by value, I'm going to explain call by address. So while implementing call by address, you will see if I'm going to change values of these a and b will be changed automatically. So now to implement call by address, I'm going to use pointer because whenever we talk about address, so automatically we need to use pointers because address of any variable can be stored in a pointer. So now focus on this call by address. So calling statement will be passing address instead of values. So I'm putting this symbol here and percent a comma and percent b. So it means I'm calling this swap function and I'm passing addresses of a and b variables. And if you want to store addresses then you need to convert the variables into pointers. So this is x pointer and this is y pointer. So this time x and y will not be having values of a and b. Instead they will be having addresses of a and b. So I am changing this. This is x. This is y. Let's say these are the beginning or base address of a and b. So x will be having one zero one and y will be having two zero one life. And here we need to put this because whenever you have pointers. So you need to use this as to this as value at address. So if I'm writing as to this as x. So it means value at address which is stored in X. So addresses one zero one. So value at one zero one, which is five. So it means here you can see a and X both are linked together to address. So a address is available with X. The address is available with Y. So whenever we change pointers with this. So pointer will actually change the values which are available on a particular address. And here also we need to use this as to this and as to this because here X and Y data time is pointed. And now if I change the values. So let's understand this that equals to as to this X. So that is a normal variable. It will be having X. So X is one zero one value at one zero one is five. So five will be stored into that. Then if we solve this as to this X equals to a stress point. So here you can write it like this as to this one zero one equals to as to this two zero one. So value at two zero one value at two zero one is 10 it will assign into value at one zero one. So value at one zero one will become 10 and that will assign into as to this five. So as to this Y means as to this two zero one. So five will be assigned into a value at two zero one. So it will change to five. So this concept is related to pointer. So to understand it more clearly personally to understand pointer and then watch this video again so that you can understand how pointer box and how pointer change. Value of the variable whose address it is containing. So X is containing address of a Y is containing address of the end with the help of this pointer calculation. You can see now value of a stand and value of these five. So before that they will print a five be 10 after completion of this function calculation. A will be printing 10 and B will be printing five because this is the current snack. So through call by address we build a relation between these variables and these pointers. So if you want to build a relation between variables of two separate functions like a and b are available in main and we want a relation. With this function. So we needed a pointer X and Y and those X and Y pointers are related to. So if we change something to X and Y for it means indirectly we are changing values of. So this way through call by address you will be having different values of. Before calling the square function and after completion of calling of that. So this way I hope you understood how call by value box and how call by address box. So now I'm going to summarize when to use call by value and when to use call by address. So if you want the change that is done in this function definition. If you want that change reflect on main then choose call by address. And if you want that whatever you are changing in function definition that is separate to main don't affect to main function then you can choose call by value. So mostly programs you might have implemented to call by value because whatever change you are doing you are returning it to a. Variable and you are using data type here but in rare of the functions you will be using call by address as well because. Here you can see we are changing two variables and through function we can return only one. So if you want to return more than one values so you cannot do with this return type because it is limited to only one. Then you can prefer call by address. So whatever change you are doing in function that is other than main and you want its reflect on main function variables. So I hope you understood whatever I explained in this video and also learn about pointer before understanding call by address. So if you want to watch those videos so you can go to description of this video and you will find links of various failures along with this pointers in C. So do watch them and thank you for watching this video.