# Include <stdio. h>
# Include <malloc. h>
# Include <conio. h>
Struct Stu {
Char name [20];
Char stuno [10];
Int age;
Int score;
} STU [50];
Typedef struct Stu elemtype;
Struct lnode
{
Elemtype data;
Struct lnode * next;
};
Typedef struct lnode;
Typedef struct lnode * linklist;
Void printstudentinfo (struct Stu E)
{
Printf ("sizeof (E. Name): % d/N", sizeof (E. Name ));
Printf ("sizeof (& E. Name): % d/n", sizeof (& E. Name ));
Printf ("strlen (E. Name): % d/N", strlen (E. Name ));
Printf ("strlen (& E. Name): % d/n", strlen (& E. Name ));
Printf ("sizeof (E. Age): % d/N", sizeof (E. Age ));
Printf ("sizeof (& E. Age): % d/n", sizeof (& E. Age ));
Printf ("sizeof (E. Score): % d/N", sizeof (E. Score ));
Printf ("sizeof (& E. Score): % d/n", sizeof (& E. Score ));
Printf ("Stu E:/T ");
Printf ("e. Name/T ");
Printf ("e. stuno/T ");
Printf ("e. Age/T ");
Printf ("e. Score/T ");
Printf ("% x/T", & E );
Printf ("% x/T", & E. Name );
Printf ("% x/T", & E. stuno );
Printf ("% x/T", & E. Age );
Printf ("% x/T", & E. Score );
Printf ("-------------------------------------------------------------------/N ");
}
Main ()
{
Struct Stu yes;
Struct Stu no;
Linklist L1;
Linklist * pl2;
Strcpy (yes. Name, "kgdiwss ");
Strcpy (yes. stuno, "20060607 ");
Yes. Age = 23;
Yes. Score = 100;
Printf ("uninitialized Stu structure:/N ");
Printstudentinfo (NO );
Printf ("initialized Stu structure:/N ");
Printf ("Yes. Name = % s/n", yes. Name );
Printf ("Yes. stuno = % s/n", yes. stuno );
Printf ("Yes. Age = % d/N", yes. Age );
Printf ("Yes. Score = % d/n", yes. Score );
Printstudentinfo (yes );
Printf ("L1/T ");
Printf ("* pl2/T/N ");
Printf ("% x/T", & L1 );
Printf ("% x/T/n", & pl2 );
}
Bytes ----------------------------------------------------------------------------------------------------------------------
Output result:
Uninitialized Stu structure:
Sizeof (E. Name): 20
Sizeof (& E. Name): 4
Strlen (E. Name): 47/* Why isn't initialization 47? */
Strlen (& E. Name): 47
Sizeof (E. Age): 4
Sizeof (& E. Age): 4
Sizeof (E. Score): 4
Sizeof (& E. Score): 4
Stu E: E. Name E. stuno E. Age E. Score
12feb4 12feb4 12fec8 12fed4 12fed8
-------------------------------------------------------------------
Initialize the stu structure:
Yes. Name = kgdiwss
Yes. stuno = 20060607
Yes. Age = 23
Yes. Score = 100
Sizeof (E. Name): 20
Sizeof (& E. Name): 4
Strlen (E. Name): 7
Strlen (& E. Name): 7
Sizeof (E. Age): 4
Sizeof (& E. Age): 4
Sizeof (E. Score): 4
Sizeof (& E. Score): 4
Stu E: E. Name E. stuno E. Age E. Score
12feb4 12feb4 12fec8 12fed4 12fed8/* hexadecimal */
1244852 1244852 1244872 1244884 1244888/* decimal */
/* Meal analysis and doubts :*/
/* 1. Note that the address of Stu e is the same as that of E. name. This proves that the starting address of the structure is the starting address of the first variable in the structure.
* 2. E. stuno-E. Name is equal to 20, which is exactly the same as char name [20] In the structure statement.
* 3. E. Age-E. stuno why is it 12 instead of 10? Isn't the statement in the structure only 10?
* 4. E. Score-E. Age why is it 4? Isn't the int type two bytes?
*/
-------------------------------------------------------------------
L1 * pl2
12ff2c 12ff28
Press any key to continue
Linklist L1;/* Is L1 a pointer or something? It points to the structure address */
Linklist * pl2;/* Here pl2 is the address pointing to the linklist, that is, the pointer */
What is the relationship between linklist L1 and linklist & L1.