By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

The "->" operator

P: n/a
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
Nov 14 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Jeff Rodriguez wrote:

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.

--
Les Cargill
Nov 14 '05 #2

P: n/a
Les Cargill wrote:
Jeff Rodriguez wrote:
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.

--
Les Cargill

Easy enough!

Thank you much.

Jeff
Nov 14 '05 #3

P: n/a
Jeff Rodriguez <ne********@gurugeek.EXAMPLENOSPAM.com> writes:
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.
--
Here's a tip: null pointers don't have to be *dull* pointers!
Nov 14 '05 #4

P: n/a
Jeff Rodriguez wrote:
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.

--
Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)

Nov 14 '05 #5

P: n/a
In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <ne********@gurugeek.EXAMPLENOSPAM.com> writes:
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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #6

P: n/a
Dan Pop wrote:
In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <ne********@gurugeek.EXAMPLENOSPAM.com> writes:

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


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.

Nov 14 '05 #7

P: n/a
"I.M.A Troll" <tr***@email.con> wrote in message news:<3F************@email.con>...
Dan Pop wrote:
In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <ne********@gurugeek.EXAMPLENOSPAM.com> writes:

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


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.
Nov 14 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.