C-Structure body

Source: Internet
Author: User

#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

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.