I computer only does (essentially) 2 things-- it adds, and it accesses memory locations-- addressing.
Many noobies are confused by the term 'pointer'. When you are learning, and even later, it is perhaps easier to think of a 'pointer' in the terms of 'address of'. So next time you say 'pointer', replace that with 'address of', instead.
As TrollKing has listed, using the '->' operator really is only used with structures.
This is because of how memory is accessed (how the compiler builds the addressing) for accessing fields in a structure.
Let's look under the hood:
Code:
typedef struct /* my structure */
{
int theNum;
char alphaStr[9];
long bigNum;
}theStruct;
void foo(theStruct*); /* a function to call */
theStruct myStruct; /* global variable */
myStruct.theNum = 10; /* some code */
strcpy(myStruct.alphaStr,"ABCDEFGH\0");
myStruct.bigNum = 123456L;
. . .
foo(&myStruct);
. . .
Further, let's say that we are 'long-word aligned'. This just means that when the compiler figures out how to address the fields in the structure, it will align the start of each field on a 4-byte boundary. Some chips require this, others simply operate faster because you're accessing data in chunks of 'native-size' to the CPU. In any event, alignment results in 'padding' unused data space within the structure.
Now, having said that (it's actually useful to know), let's look at what this structure actually looks like in RAM (we'll assume it sits at location 0x001F5B9A.
Code:
Address RAM (Bytes)
-----------------------------------------------------------------
001F5B9A 00 0A 00 00 40 41 42 43
001F5BA2 44 45 46 47 00 33 0D 16
001F5BAA 00 01 E2 40 DD F7 1C 09
001F5BB2 78 00 00 FF FF FF C7 8A
. . .
In memory, as you can see by the raw coredump above, the address where the structure starts is 0x001F5B9A. If we were to break RAM up by structure field, it would look like this:
Code:
Address RAM (fields in bytes)
-----------------------------------------------------------------
001F5B9A 00 0A ;theNum (10 decimal)
001F5B9C 00 00 ;pad bytes
001F5B9E 40 41 42 43 44 45 46 47 00 ;alphaStr
001F5BA7 33 0D 16 ;pad bytes
001F5BAA 00 01 E2 40 ;bigNum
. . .
Okay, now that you have some understand of how things look in RAM, understand that the compiler references the structure based on the address of the first byte of the structure itself (0x001F5B9A). All the fields are referenced by offset (0x001F5B9A+0x0 [0d] = theNum, or 0x001F5B9A+0x4 [4d] = alphaStr, or 0x001F5B9A+0x11 [17d] = bigNum).
When you have a function where the structure variable has been declared/defined within it, you access the fields of the structure using '.'-- this is because the compiler will calculate the offsets to each field- relatively. You are working with the actual structure, not a pointer to the structure.
When you pass the address of the structure variable to another function (like foo(), above), foo() doesn't have the structure, it just gets the address of the variable which contains the address of the structure-- a pointer.
Thus, you use '->' to go _indirectly_ through the contents of the variable passed-- which is the address of the structure in RAM.
I'm sorry I can't draw a picture-- pictures are so much simpler. Hopefully, my example above will also teach you other things.