#include<stdio.h>intMainintargcConst Char*argv[]) { //defining struct Types structPerson {Char*name; intAge ; DoubleHeigth; }; //4 ways to initialize//1. Simultaneous initialization of the definition structPerson P1 = {"Zhangsan", -, the}; //2. First define and then initialize one by one structPerson p2; P2.name="YKD"; P2.age= -; P2.heigth= the; //3. First define and initialize once again structPerson P3; P3= (structperson) {"Lisi", -, the}; //Note: The difference between struct and array here is that arrays cannot be defined first and then initialized once//the struct should explicitly tell the system {} that it is a struct//4. Specify that the data is assigned to the specified property structPerson P4 = {. heigth=1.77,. name="Wangwu",. age= -}; //How do I fetch data from a struct? printf"name=%s,age=%i,heigth=%f\n", p4.name,p4.age,p4.heigth);//name=wangwu,age=33,heigth=1.770000 return 0;}
C + + struct body initialization