C + + struct body initialization

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.