#include <stdio.h>//struct: Can consist of several different types of dataintMain () {structPerson {//the 3 variables, which can be referred to as members or attributes of a struct. intAge ; Doubleheight; Char*name; }; structPerson p = { -,1.55,"Jack"};//depending on the struct type, the struct variable is defined,,,, and the member can be assigned sequentially only when the struct variable is defined. P.age = -; P.name="Rose"; return 0;}
#include <stdio.h>intMain () {//1. Define the struct type (and do not allocate storage space) structDate {intYear ; intmonth; intDay ; }; //2. Defining struct variables (really allocating storage space) structDate D1 = { .,4,Ten}; structDate D2 = { .,8,9}; //The values of all members of the D1 are assigned to all members of D2D2 =D1; return 0;}
From small to large, from the top down
#include <stdio.h>intMain () {structStudent {intAge ; Char*name; } structStudent Stu; Stu.age= -; Stu.name="Jack"; ints =sizeof(Stu); printf ("%d\n", s); return 0;}//the output is://Completion algorithm, the structure of the occupied memory space, must be the largest member of the storage space in multiples,
Variables are defined in many ways:
#include <stdio.h>intMain () {/*mode one://1. type struct Student {int age; Double height; Char *name; }; 2. Variable struct Student stu = {1.78, "Jack"}; */ //Mode two structStudent {intAge ; Doubleheight; Char*name; } Stu;//equal to the way one structStuent STU2;// return 0;}
C-Structure body