Meaning of (indirect member operator) in C language

Source: Internet
Author: User

Written on December 12, 2016.

"," is called an indirect member operator.

General Note: This operator is used with pointers to structs (STURCT) or unions (union) to indicate the members of a struct or union. Suppose Ptrstr is a pointer to a struct, member is a member specified by the structure template.

So

Ptrstr->member

This expression represents the member of the structure being pointed to. Indirect member operators can also be used in the same way for unions.

Example

struct{

int code;

float cost;

} Item *ptrstr;

ptrstr=&item;

ptrstr->code=3451;

The last statement first points ptrstr to code, and then assigns an int value of 3451 to the member of item code. The following three expressions are equivalent:

Ptrstr->code

Item.code

(*PTRSTR). Code

Meaning of (indirect member operator) in C language

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.