The "->" operator

J

Jeff Rodriguez

What does this do? I've been looking online and I've seen mention that it exists
as well as examples to it's use but still no explination as to exactly what it does.

TFTH,
Jeff
 
B

Ben Pfaff

Jeff Rodriguez said:
What does this do? I've been looking online and I've seen mention that
it exists as well as examples to it's use but still no explination as
to exactly what it does.

The -> operator dereferences its left operand, then accesses one
of the members of the referenced object (which must be of
structure or union type). a->b is equivalent to (*a).b. The ->
operator is simply there to reduce the need for parentheses in
accessing a structure member through a pointer.
 
L

Les Cargill

Jeff said:
What does this do? I've been looking online and I've seen mention that it exists
as well as examples to it's use but still no explination as to exactly what it does.

TFTH,
Jeff

It's a struct dereference by pointer.

struct V a;
struct V *b;

b = &a;

a.<something> and b-><something> are now exactly the same thing.
 
J

Jeff Rodriguez

Les said:
It's a struct dereference by pointer.

struct V a;
struct V *b;

b = &a;

a.<something> and b-><something> are now exactly the same thing.
Easy enough!

Thank you much.

Jeff
 
L

Lew Pitcher

Jeff said:
What does this do? I've been looking online and I've seen mention that
it exists as well as examples to it's use but still no explination as to
exactly what it does.

The -> operator is a structure element pointer dereference operator. It
takes a pointer to a structure on the left and a membername on the right,
and results in the value of the member of the structure as pointed to by the
pointer.

In other words, assuming something defined like

struct { int number } *pointer;

then

pointer->number

is a shortform for

(*pointer).number

That's it.
 
D

Dan Pop

In said:
What does this do? I've been looking online and I've seen mention that it exists
as well as examples to it's use but still no explination as to exactly what it does.

What does your favourite C book say about it?

Dan
 
I

I.M.A Troll

Dan said:
What does your favourite C book say about it?

Dan

Dan, it wasn't necessary to lapse into sarcasm. Why not just follow the
example of the prior respondents and answer the question in a serious
and congenial manner (or refrain from making any reply if the question
has already been answered)? Expertise does not excuse bad manners.
 
J

John Bode

I.M.A Troll said:
Dan, it wasn't necessary to lapse into sarcasm. Why not just follow the
example of the prior respondents and answer the question in a serious
and congenial manner (or refrain from making any reply if the question
has already been answered)? Expertise does not excuse bad manners.

This could be a sign I've been hanging around c.l.c. too long, but
Dan's answer is perfectly appropriate (if a bit brusque, but that's
part of Dan's charm). Answers to basic questions such as this are
best found in your handy C reference manual, not in an online
newsgroup where there is some delay in getting an answer, and where at
least one of the answers you get will be wrong or useless.

The OP needs to get into the habit of checking his C reference manual
*first*; if he has additional questions, he needs to check out the
FAQ; and then, if he still needs guidance, ask a question here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top