[Dev-C++] Some doubt question about the pointer of the link's struct?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <per...@ya...> - 2004-06-07 01:16:03
|
The pointer p is the head pointer of the link list.And the p1 is point to p's next link node.After I use the function malloc() to distribute continuous memory to p and p1.Why the the result of p1-p is 16 not 12 which is the size of the struct student?The p->next is a pointer to p's next link node,also ++p.But why p->next is not equal to ++p? Please forgive my ignorance,I hope someboby can tell me why.
---Thanks,
Bruce.J
/* ** ******************************** */
The program run result is belove:
The size of "int" is 4
The size of "p->next" is 4
The size of "struct student" is 12
p->next = 8783360
p1 = 8783360
p = 8783344
++p = 8783356
/* ******************************** */
My program is list belove:
#include <stdio.h>
typedef struct student {
int number;
int grade;
struct student *next;
}student, *stuLink;
main()
{
stuLink p, p1;
p = (stuLink) malloc(sizeof(student));
p1 = (stuLink) malloc(sizeof(student));
p->next = NULL;
p1->next = p->next;
p->next = p1;
printf("The size of int is %d\n", sizeof(int));
printf("The size of p->next is %d\n", sizeof(p->next));
printf("The size of struct student is %d\n", sizeof(Student));
printf("p->next=%d\n", p->next);
printf("p1=%d\n", p1);
printf("p=%d\n", p);
printf("++p=%d\n", ++p);
free(p);
free(p1);
system("PAUSE");
}
---------------------------------
Do You Yahoo!?
嫌邮箱太小?雅虎电邮自助扩容! |