Definition and reference of structure array (v)

Source: Internet
Author: User
Tags printf

2) Pointer method
If p points to an element of an array, p++ points to its subsequent elements.
3 array notation of pointers
If p=student, we say that pointer p points to array Student,p[i] represents the first element of an array, with the effect
Student[i] equivalent. A reference to an array member is described as: P[i].name, P[i].num, and so on.
[Example 7-4] uses a pointer variable that points to an array of struct bodies.
STRUCTDATA/* definition Structure Type * *
{
Intday,month,year;
};
STRUCTSTU/* definition Structure Type * *
{
Char name[20];
Long num;
struct data birthday;
};
Main ()
{inti;
structstu*p,student[4]={{"Liying", 1,1978,5,23},{"wangping", 2,1979,3,14},
{"Libo", 3,1980,5,6},{"Xuyan", 4,1980,4,21}};
/* Defines an array of structures and initializes it.
P=student;/* assigns the first address of the array to the pointer p,p a one-dimensional array student*/
printf ("\n1----outputname,number,year,month,day\n");
for (i=0;i<4;i++)///* The members of the array element are output by the pointer method */
printf ("%20s%10ld%10d//%d//%d\n", (P+i)->name, (p+i)->num,
(P+i)->birthday.year, (p+i)->birthday.month,
(p+i)->birthday.day);
}

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.