struct precedence

In following expression:

*p++->str

Assume p is a pointer to a struct: e.g. struct point *p;

Highest precedence ->. The -> operator first dereferences p and returns the value of the member: so p->x ==(*p).x

Next precedence is * which dereferences the first element of str which is a char array. So if str is a char array pointing to {'h', 'e','l','l','o}, what we get back with * is the character 'h'.

then we increment h??? Makes no sense.
What don't you understand about incrementing the first element of the char array str? A char can be incremented just like any other variable.
And what is 'h' incremented to? i?
In essence, yes. The char type is really just a single-byte integer that holds the ASCII code of a character. 'h' is just a way to refer to 104, the ASCII code for the character 'h'. Incrementing it yields 105, which happens to be the ASCII code for the character 'i'.
Highest precedence ->

not quite: post-increment and -> have equal precedence:
http://en.cppreference.com/w/cpp/language/operator_precedence

The expression *p++->str is thus parsed as (* ((p ++) -> str))

we get back with * is the character 'h'.
then we increment h??? Makes no sense.

no, the argument of the post-increment operator ++ is the pointer p. That's what is being incremented.
Topic archived. No new replies allowed.