 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can add two complex numbers using structure and pointer in C programming. Before starting, you can note how you can search my YouTube channel. You can type my name Sanjay Gupta in YouTube search. My channel will be available there on first page. You can watch various programming related videos there. Now I am going to implement solution of this problem. So first I have I have included a header file that is STDIO.H. Then I am declaring a structure whose name is complex. It is having two members in real and imaginary. Now I am defining main function inside main. I am declaring three variables C1, C2 and C3 and three pointers P1, P2 and P3. So I will be reading and printing complex numbers through C1, C2, C3. But for addition purpose or for processing purpose, I will be using these three pointers that are P1, P2 and P3. So first I am going to read values of first complex number. So this message will be displayed enter first complex number then through scanf I can read values from user. So you can see the statement scanf %d %d then %c1.real and %c1.imaginary. So this way first complex number will be received from user then enter second complex number. This message will be displayed on output screen. Now again scanf will receive the information in C2.real and C2.imaginary. So this way I have successfully received two complex numbers from user. Now I am going to assign addresses of these structure variables into structure pointers. So this way I have implemented these three instructions. Address of C1 structure variable is assigned into P1 structure pointer. Similarly C2 address into P2 pointer and C3 address into P3 pointer. Now I can access values of C1, C2, C3 through these P1, P2, P3 pointers. So for addition purpose I am writing this. So watch this statement carefully here P3 arrow real equals to P1 arrow real plus P2 arrow real is written. So whenever I want to access members of structure through its pointer then I have to use this arrow notation. And if you are accessing members of structure through its variable then you have to use only dot operator. So this is the difference between structure variable and structure pointer. Now you can easily add imaginary values through these pointers. So now I have added values of C1 and C2 through this through these P1 and P2 pointers. These are stored inside C3 because P3 is having address of C3 variable. So if I am modifying P3 pointer then it automatically modifies the values of C3. Now we have to check whether it will work or not. So here I am applying if condition which is based on C3 dot imaginary. If it is greater than equals to 0. Now I am going to print output in this format 5 plus I6. Here 5 is real value then plus Iota and then 6 is imaginary. If minus Iota is available then output will be like this 5 minus Iota and 6. In both the cases imaginary value will be displayed in positive form because Iota is representing whether imaginary value is negative or positive. Now if I am printing positive complex number I am writing this print f percent d then plus I percent d then C3 dot real comma C3 dot imaginary. You can see that I have received addition in P3 pointer but I am printing the result through C3 variable. Why I am doing so because P3 is having address of C3. So if I modifying P3 pointer it automatically modifies the values of C3. Then else print f slash n percent d minus Iota percent d then comma C3 dot real comma. Now I am calling a function abs which converts negative values into positive. And this abs method is declared in math dot h header file. So this abs is a predefined function which is declared in math dot h. So I have to include that header file first. So remember that abs is a predefined function which find out positive values of any number whether it is containing negative or positive. So if C3 dot imaginary is negative then it will be converted into positive and then it will be displayed on output screen. So now I am going to execute this program in both the ways. In one way Iota will be negative and in another way it will be positive. Now I am going to execute this code. So it is asking for first complex number. I am entering one one. It is asking for second complex number. I am entering two two. So you can see the output real values three then plus Iota and then three. So it is working properly. Now again I am executing this code. This time I am entering two and minus two and four and minus four. So here imaginary value is negative. So you can see the output six is real part minus Iota and then six. So here imaginary value is minus six but it is printed in positive format because I have called abs function for printing this imaginary value. But Iota is printing in negative form. So it is representing that imaginary value is a negative number. So this way I have implemented addition of two complex numbers with the help of pointers. I hope you have understood how I have used structure variables and structure pointers together for this purpose. If you want to watch more programming related videos you can search my name Sanjay Gupta in YouTube. My channel will be available there. You can watch videos programming related videos on my channel. Thank you for watching this video.