Detailed _c language based on structure body and pointer

Source: Internet
Author: User
structure pointer variable:Description of the structure pointer variable and use a pointer variable to point to a struct variableWhen
values in a struct pointer variableis the The first address of the structure variable to point to。 The struct variable is accessed through the structure pointer, which is the same as the pointer and function pointer of the array element.
the general form of the description of the structure pointer variable is:
struct structure name * structure pointer variable name
For example: struct Stu *pstu;
The general form of its access is:
(* structure pointer variable). Member Name: (*pstu). Num
Or as:
struct pointer variable-> member name: Pstu->num
It should be noted that the brackets on both sides of the (*pstu) are not small, because the member character "." Priority is higher than "*". If you remove the bracket writing *pstu.num is equivalent to * (Pstu.num), so the meaning is completely wrong.
structure variables. Member name
(* structure pointer variable). Member name
struct pointer variable-> member name
these three forms for representing struct members are completely equivalent.
structure array pointer variable: A struct pointer variable can point to an array of structures, at which point the value of the struct pointer variable is the first address of the entire structure array. A struct pointer variable can also point to an element of a structure array, at which point the value of the struct pointer variable is the first address of the array element of the structure.
Set PS to a pointer variable that points to an array of structures, PS also points to the No. 0 element of the structure array, ps+1 points to the 1th element, and ps+i to the I element. This is consistent with the case of an ordinary array.
Copy Code code as follows:

#include <stdio.h>
int main (void)
{
int i;
struct student
{
long int num;
int age;
char* name;
}st[3]={{198,19, "Zhangsan"}, {199,18, "Lisi"},{200,19, "Wangwu"}};
struct student* p;
p=st;
printf ("/n/n NO. Age name/n ");
for (;p <=st+2;p++)
printf ("%ld%d%s/n", p->num,p->age,p->name);
Getch ();
printf ("/n/n NO. Age name/n ");
For (p=st;p <=st+2;p++)
printf ("%ld%d%s/n", (*p). Num, (*p). Age, (*p). Name);
Getch ();
return 0;
}

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.