* (1 + & foo) is the same as * (& foo + 1) in C / C ++?

It:

*(1 + &foo)

same as this?

*(&foo + 1)

'+' and '&' have the same priority, and they are evaluated from right to left. However, you cannot interpret the second case as follows:

*(&(foo + 1))

... because you can only use '&' with an l-value (it won’t even compile if you write it like that). So will it be rubbish? Or will he safely find out what you had in mind?

+3
source share
3 answers

Yes, they are equivalent (the third, obviously, no).

& , + ( ), &foo + 1 (&foo) + 1. , , , , + ( ) , &.

+9

, . , + , &. , +.

+1

, & + + - , a - +b.

When interpreted +as a binary operator, it has a lower priority than &, therefore, the second case will be interpreted as *((&foo) + 1), rather than *(&(foo + 1)).

+1
source

Source: https://habr.com/ru/post/1788073/


All Articles