I learned the struct, and understood it by inputting the simplest struct to the struct array, struct pointer, and struct as function parameters, including the structure of the structure, each of which is coded, in addition, the stack is also learned. first, then, and first, the heap needs to be allocated by itself. At the same time, it must have a clear pointer. Otherwise, it will not be found. malloc, calloc, realloc and other functions are allocated memory. A small space is allocated to a large space, and the heap is allocated from the bottom up. the linked list is still in practice.
# Include <stdio. h> # include <string. h> struct student/* student structure */{char cname [20]; // name int inumber; // learn char csex; // gender int igrade; // age} student; int main () {struct student * pstruct; // define struct pointer pstruct = & student; // pointer to struct variable strcpy (pstruct-> cname, "suyuquan"); // copy the regular string to the member variable pstruct-> inumber = 12061212; // assign pstruct-> csex = 'w' to the member variable '; pstruct-> igrade = 2; printf ("---- the student's information ---- \ n"); // The message prompts printf ("Name: % s \ n", student. cname); // use the variable to directly output printf ("number: % d \ n", student. inumber); printf ("Sex: % C \ n", student. csex); printf ("grade: % d \ n", student. igrade); Return 0 ;}
struct Student{ char cName[20]; int iNumber; char cSex; int iGrade;}student[5]={{"wangjiasheng",12062212,‘M‘,3}, {"yulongjiao",12062213,‘W‘,3}, {"zhangmeng",12062214,‘W‘,3}, {"jiangxuehuan",12062215,‘w‘,3}, {"hanliang",12062216,‘M‘,3}};int main(){ struct Student*pStruct; int index; pStruct=student; for (index=0; index<5; index++,pStruct++) { printf("NO%d student:\n",index+1); printf("Name:%s,Number:%d\n",(*pStruct).cName,pStruct->iNumber); printf("Sex:%c,Grade:%d\n",pStruct->cSex,pStruct->iGrade); printf("\n"); } return 0;}
struct Student{ char cName[20]; float fScore[3];}student={"suyuqun",98.5f,89.0,93.5f};void Display(struct Student* stu){ printf("------unformation------\n"); printf("Name:%s\n",stu->cName); printf("English:%.2f\n",stu->fScore[2]); stu->fScore[2]=90.0f;}int main(){ struct Student* pStruct=&student; Display(pStruct); printf("change english:%.2f\n",pStruct->fScore[2]); return 0;}
struct date{ int year; int month; int day;};struct student{ char name[30]; int num; char sex; struct date birthday;}student={"WangWei",12345678.,‘M‘,{1986,12,6}};int main(){ printf("-------information---------\n"); printf("Name:%s\n",student.name); printf("Number:%d\n",student.num); printf("Sex:%c\n",student.sex); printf("Brithday:%d,%d,%d\n",student.birthday.year, student.birthday.month, student.birthday.day); return 0;}
Application and understanding of struct. Ninth day of Camp David