I saw some code here and somebody decaled a type like:
POINT pt;
Now here accessed the "x" value in the variable pt like this:
switch(pt -> x)
Can I write the samething as:
switch(pt.x)
Is there any difference when you use "->" and "." ?
Printable View
I saw some code here and somebody decaled a type like:
POINT pt;
Now here accessed the "x" value in the variable pt like this:
switch(pt -> x)
Can I write the samething as:
switch(pt.x)
Is there any difference when you use "->" and "." ?
There's a big difference. See the other threads about -> because I don't want to type it out again ;)
when you have a pointer, you use -> to access it's members, if it's just a regular variable you use .Quote:
Originally posted by abdul
I saw some code here and somebody decaled a type like:
POINT pt;
Now here accessed the "x" value in the variable pt like this:
switch(pt -> x)
Can I write the samething as:
switch(pt.x)
Is there any difference when you use "->" and "." ?
Code:struct test{
int x;
};
test tVar;
test* tpVar;
tVar.x = 5; //yes
tpVar.x = 5; //no
tpVar->x = 5; //yes
(*tpVar).x = 5 // yes
I have read about pointers but just forgot a bit so
Can you explain the examples which you gave me (a kind of another approach) because i did not understand the "struct" and then a bracket and then "You have declared a variable"
Can you explaim me please that what is happening in that example
That would be really helpfull
In fact, an expression involving the member-selection operator (->) is a shorthand version of an expression using the period (.) if the expression before the period consists of the indirection operator (*) applied to a pointer value. Therefore,
expression -> identifier
is equivalent to
(*expression) . identifier
when expression is a pointer value.