Code: Select all
a) b) c)
+->100 +->200 +->300
| | |
PtrParIn{100}----+ PtrComp{200}----+ PtrComp{300}----+ PtrComp{null}
Discr{0} Discr{0} Discr{0}
EnumComp{0} EnumComp{0} EnumComp{0}
... ... ...
When you do PtrParIn->PtrComp->PtrComp you are getting value 300. When you de-reference it (via &) you should be getting address 200 since the de-reference operator asks for the address instead of the value of that variable. Thus you are able to change its value (by re-referencing it via *) from 300 to some other value, i.e. *200 says go to address 200 and change the value contained at that address
(Note that *200 is not valid C syntax since you obviously never put * in front of a literal numeric address, you'd put it in front of a variable containing that address...I just did that to demonstrate my point...for those that haven't seen how de-reference/re-reference works in C, look at the last code snippet that shows how it's used.)
Code: Select all
addr1 = PtrParIn->PtrComp; /* addr1 equals 200 */
addr2 = PtrParIn->PtrComp->PtrComp; /* addr2 equals 300 */
addr3 = &PtrParIn->PtrComp->PtrComp; /* addr2 equals 200 since you are asking for address of who's pointing to it */
Code: Select all
NextRecord = PtrParIn->PtrComp;
addr1 = NextRecord; /* addr1 equals 200 */
addr2 = NextRecord->PtrComp; /* addr2 equals 300 */
addr3 = &NextRecord->PtrComp; /* addr3 equals 200 again */
Code: Select all
Proc3(PtrParIn->PtrComp->PtrComp);
...
Proc3(PtrParOut)
RecordPtr * PtrParOut;
{
*PtrParOut = 400; /* this would change what is at address 300 */
}
Code: Select all
NextRecord = PtrParIn->PtrComp;
Proc3(&NextRecord->PtrComp);
...
Proc3(PtrParOut)
RecordPtr * PtrParOut;
{
*PtrParOut = 400; /* this would change what is at address 200 */
}