C language----Structure--declaration and definition

Source: Internet
Author: User

Try to write something, mainly to consolidate what you have learned.

The structure of the body? The structure of C language is mainly used to express, define some of the types you want, such as date, identity information and so on.

Date: 2017-09-10

Identity information: Name Fakke, age 23, height 180;

Can be implemented through structs. (Personal feeling a bit like a python dictionary)

Define the way:

First step: Declare the struct type:

struct type name {

Variable type 1 variable name;

Variable type 2 variable name;

。。。

Variable type 3 variable name;

};

Step Two:

2 Defining a new variable
struct date variable name;

Step Three:

Variable Assignment initial value
struct Date today = {07,12,2017};
struct Date today = {. month=01,.year=2012};
Two assignment methods, no default 0 specified, such as an array.

There are two ways to declare data types, of course.

One is:

struct {

}P1,P2;
P1,P2 is the two variable of this nameless type, which you might just need to use, without having to declare a data type.

The other is:

struct Point {

}P1,P2;
This method of declaring the data type, while doing two things, one is declaring one type, and the other is creating two variables.

C language----Structure--declaration and definition

Related Article

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.