#include <stdio.h>
struct node{
int data;
struct node*link;
};
typedef struct node x;
x*head,*k;
int main(void) {
int n=10,i=0;
for( ;i<n;++i){
if(head==NULL){
x*temp=malloc(sizeof(x));
temp->data=i;
head=temp;
k=temp;
}
else
{
x*temp1=malloc(sizeof(x));
k->link=temp1;
k=temp1;
k->link=NULL;
}
}
while(head!=NULL){
printf("%p\t%p\n",head,head->link);
head=head->link;
}
return 0;
}
----------------------------------------------------------------------
look at the output!
If you run this code,you w'll never get the same output as:
0x9304078 0x93040a0
0x93040a0 0x93040c8
0x93040c8 0x93040f0
0x93040f0 0x9304118
0x9304118 0x9304140
0x9304140 0x9304168
0x9304168 0x9304190
0x9304190 0x93041b8
0x93041b8 0x93041e0
0x93041e0 (nil)
visualize the 1st node holds the address of 2nd node.
according to the program,what will be the head and tail of this list?
obviously head is "0x9304078" and tail is (nil) or NULL.