You are using a version without Ads of this website. Please, consider donating:

### what does "->", "&=" and "|=" means?

 ``12345678`` ``````if (a) { b->c |= d; } else { b->c &= ~d; } ``````

Above code means, if a is true, things inside bracket will execute right?
Then what does "->", "&=" and "|=" means?

Thank you.
Last edited on
-> is an operator used to access members of classes and structs. It is used when the variable is a pointer to a data structure. So in that example, b is a pointer to something and you are accessing member c of b
The arrow operator is a less verbose way of writing (*b).c which does the exact same thing

 `c &= ~d`
is the same thing as writing
 `c = c & ~d`

And
 `c |= d`
is the same thing as writing
 `c = c | d`
Last edited on
Hi maeriden,

Thanks indeed for your explanation. It is indeed very helpful and clear. :)

as for "c &= ~d" my understanding is as below.

~d meaning invert bits of d
c &= ~d will do bit wise AND operation between c and inverted bits of d, then result will store in c.

Please correct me if i am wrong.

 ~d meaning invert bits of d c &= ~d will do bit wise AND operation between c and inverted bits of d, then result will store in c.

That's correct. The same applies to operator |=
regarding `->`, it means that b is a pointer to some structure or class that has c as a member. You're just using c from that class.

like so:
 ``123456789101112`` ``````struct SomeType { int a; int b; int c; }; SomeType o; // Creates object o; cout << o.c; // outputs the value of c SomeType* p = &o; // Creates pointer p, it points to object o cout << p->c; // outputs the value of c ``````

Edit: Fixed &o as maeriden noticed.
Last edited on
Stewbond,

Thanks a lot. It is a very good example :)
There's a typo, it should be
SomeType* p = &o
Topic archived. No new replies allowed.