dangling (i.e.,
pointing nowhere).
Such a pointer can be assigned to NULL, a constant indicating there is no valid
address in this pointer, using the following statement:
B.p = NULL;
The data elements in this linked structure can be assigned by the following statements:
A.data = 70;
B.data = 80;
The linked structure now looks as follows:
Note that the members of structure B can be reached by two methods:
(a)
From its variable name B through the dot operator
(b)
From the pointer p of variable A, because it is also pointing to structure B; in this case
an arrow operator is used.
That is,
printf(“\n The contents of member data of B= %d”, B.data);
printf(“\n The contents of member data of B= %d”, A.p->data);
Thus, both of these statements will give the same output as follows:
The contents of member data of B= 80.
Example
Do'stlaringiz bilan baham: |