 Welcome back in the last segment we did a somewhat detailed example of how structures could be used and how they might presumably improve the readability of our programs. Now in this segment we are going to talk about how pointers can be used in conjunction with structures and we will also have a conclusion for this entire lecture sequence of segments. So you have seen pointers earlier and pointers to structures are created in a natural manner. So we have in this statement we are defining a disk, so this is a disk a variable of type disk and we are also defining a pointer to a structure or variable of type disk. So that pointer is dptr and I will just remind you what this is, so this is a disk, so I guess we have had two kinds of disks now but this is a disk in which we had the first member was a point and here we are saying that the x coordinate is 2, the y coordinate of that center is 3 and then the radius is 4, yeah. Now you can do the normal pointer operations on structure pointers as well, so for example I can write dptr equal to the address of this disk type variable d1, so that is what you normally do and then I can take I can dereference this dptr as well. So if I dereference this dptr what do I get? I get d1 itself but then I can take its radius member and I can say that look I want the radius to be 5 rather than the 4 that it currently is, so that is what this statement is going to do. Now this idiom star x dot comes up quite frequently and therefore C plus plus gives a different way of writing it, so here is another operator the arrow operator which is made up of the characters minus and greater than you should read it as arrow. So star x dot y can be written as x arrow y, so in x arrow y this x should be a pointer and y should be a member. So I could have written this statement as this, so I could have written dptr arrow radius equals 5 not dptr dot radius. If I want to write dptr dot radius and dptr had better been had better be a disk type variable but dptr is not a disk type variable it is a pointer to a disk type variable and therefore I should use this arrow which dereferences first as well. Now pointers can be structure members as well, so I can have struct disk 2 which has double radius and which has point but this time my member is not a point but it is a point star or it is a pointer to a point, so center ptr not center ptr equal to address of p. So this is a pointer and into it I am storing the address of this point. Now I want to print the x coordinate of the center of this disk d, so how do I get to that? So I get to d dot center ptr which gives me a pointer to the point which is the center and since this is a pointer and I want the x variable the x member of it I write arrow x, then I can have disk 2 f, so f is another disk 2 and maybe I can set its center ptr also to this same point. So essentially these I am making these to be concentric disks but there is a subtle point over here if I change this, if I change the center of this then the center of this also changes. So you should do this only if you intend that and yes this might be a possible motivation for using pointers so that we can have disks which are sharing the centers and we can do similar things we can set f dot center ptr x equals 15 and that will set the coordinate for the disk d as well. So this will also print out 15. Now with pointers especially in this current context we might want to say that a particular pointer is not pointing to anything at all. So for that there is a keyword null which is reserved so it can be assigned to any pointer to indicate the pointer does not contain does not point to anything meaningful. We have remarked long ago that a pointer to disks cannot be assigned to a pointer to points but null is kind of a universal pointer. So you can assign you can store null into any kind of pointer. You can essentially you can say that this particular pointer does not point to anything at all and you can check whether pointer points to nothing by writing ptr equal to equal to null. Here is an example where we have pointers to the structure of the same type. So we have a struct employee but inside it is an employee pointer. So boss is a pointer to another employee. This is allowed. This looks like it is referring to itself. In some sense it is but what the purpose of writing this at least in this limited context is we need to know how much space to reserve for this employee ptr or this member boss. But all ptrs essentially have the same amount of space and therefore this is okay and this of course says that subsequently if you use boss it is expected to point to a variable of type employee. So here is how we might create employees. So this says even is precedent, so the title is precedent and there is no boss. So presumably we might be writing this for somebody who is the head of that institution. So that person does not have a boss. So its boss is pointing to null. There might be an MD in that institution, a managing director and maybe the managing directors boss is the president. So here we can supply the address of the president and so address of even is supplied over here. Similarly E3 maybe the executive director has as boss the president. So here we are supplying the address of that president. Now we can do this, so we can say E2.boss so we get to this address of even over here and we want to print out the title of that person. So to get to the title the title is a member of even but we have an address of even and therefore we should put an arrow here. So this will print president. Now if we write E3.boss we will get to even, we will get a pointer to even. If we take its boss member we arrow to boss then we will get null. So if we then print it out, then take the title then we are making a mistake because null is not pointing to anything. So we cannot take a title of it and therefore this is going to cause an error. So at execution time the program will say that there is something wrong. So what did we discuss in this lecture? So we talked about structures and we said that structures enable us to group together variables of different types. Now I should note that arrays also group together variables but in arrays the variables are of the same type whereas in structures they can be of different types. They may be of the same type but they can be of as many different types as you want. A structure name behaves like a variable. So the structure name does not denote the address of that structure but it denotes the content of that structure. So if you pass it or if you copy it that content gets copied. Again this is something different from the way array names behave. And then why we got on to this, we did all this because by grouping things together we can reduce the clutter in our argument lists and we can organize our data better and because our clutter is reduced we are more inclined possibly to write smaller functions and this functions can be written at different levels. So as we saw in the example the main function was written at a very high level. So whereas the other functions sort of dealt with the internals of the disks whereas the main function just said oh here I do these things with a disk without really worrying about what is going on inside. So let me conclude this lecture then by saying that disk that structures are a way by which you can improve the readability of your program because they help you to group all the attributes associated with an entity into a single structure or a single super variable. And as always I will suggest that please look at the problems at the end of this chapter. Of course the next lecture will also continue with chapter 17. So maybe you can wait until the next lecture to look at the problems at the end of chapter 17. Thank you.