# What's the difference?

## Recommended Posts

cherryhouse    100
I just saw somebodies signature that reminded me to ask this question. What is the difference between "->" and "."? I'm pretty sure -> has to do with pointers but Why use it if . can do the same thing, or at least that's what I think. for example: You can use these both and they would work the same.. if(cat.brown == TRUE) and if(cat->brown == TRUE) So, in what case would -> be necessary to use?

##### Share on other sites
Alpha_ProgDes    6935
struct test {    int data;} *one, two;one->data = 23; (*one).data = 23; //same as abovetwo.data = 25; // this is not a pointer!

Hope that clarifies somewhat.

##### Share on other sites
Tera_Dragon    260
You are correct, the -> operator is for use with pointers. The reason (or the only one I can think of) is to be able to easily see if a variable is a pointer or not.

##### Share on other sites
cherryhouse    100
That's kind of what I figured, thanks.

##### Share on other sites
moeron    326
Quote:
 Original post by Tera_DragonYou are correct, the -> operator is for use with pointers. The reason (or the only one I can think of) is to be able to easily see if a variable is a pointer or not.

I think Alpha_ProgDes showed what the benefit is...
// quicker to typeptr->foo();// slow to type(*ptr).foo();// not to mention confusion is avoided...*ptr.foo( ); // not the same as (*ptr).foo()

##### Share on other sites
kuphryn    210
Correct. In practice, -> takes more work than .. In theory, or at least visually, -> is a pointer.

Kuphryn

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account