1211.1--Structural Body

Source: Internet
Author: User

Simple structural Body

struct student{

Char name[20]; can be scanf or directly assigned to a value

* If you use char *name when using scanf, no memory is received

Long ID;

int age;

float height;

};

A struct can only declare variables that cannot be assigned an initial value.

struct student Zhangsan;

struct Student Zhangsan = {"Xiaowang", 2000002,20,180.5};

The structure is accessed using "." : Xiaowang.name

typedef

typedef struct student{

Char name[20]; Cannot use char *name when using scanf without memory reception

Long ID;

int age;

float height;

}student;//typedef take an alias for an existing type

Student Zhangsan;

Student Zhangsan = {"Xiaowang", 2000002,20,180.5};

If you do not add a typedef:

struct student{

Char name[20]; Cannot use char *name when using scanf without memory reception

Long ID;

int age;

float height;

}student;//student is a variable.

struct-Body pointer

Student *s;

If *name is a string s->name = "Xiaowang";

If name[] is an array to receive strcpy (S->name, "Xiaowang");

S->age = 23;

Student *s[5]; Each piece has the address of the structure.

Student XW ={"Xiaowang", 2345,23,164.3};

S[0] =&xw; Each of the struct pointer arrays contains an address, and if you do not give him a memory address, its value is empty and cannot be directly assigned.

S[0]->age = 20;

struct array

Student array[5] ={};

strcpy (Array[0].name, "Xiaowang");

Array[0].age = 23;

1211.1--Structural 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.