445,797 Members | 1,848 Online
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
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. and b-> 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 existsas 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. and b-> are now exactly the same thing. -- Les Cargill Easy enough! Thank you much. Jeff Nov 14 '05 #3

 P: n/a Jeff Rodriguez 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 Jeff Rodriguez writes: What does this do? I've been looking online and I've seen mention that it existsas 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 Jeff Rodriguez writes:What does this do? I've been looking online and I've seen mention that it existsas 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