What is the difference b/w
struct {
float *p;
}*ptr=s;
*ptr->p++
and
(*ptr->p)++;
I understand that the former points to the next address while the latter increments the value by 1 but I cannot get how it is happening.....
It's all about precedence.
In the first example you are incrementing the location that *p points to.
In the second example you are dereferencing *p and incrementing the value.
Due to C operator precedence,
*ptr->p++;
is equivalent to
*(ptr->p++);
so it actually increments the pointer, but dereferences the original address, due to the way postfix ++ works.
However, since nothing is done to the dereferenced address, the statement is equivalent to
ptr->p++;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With