Errors, bugs, questions - page 162

 
mql5:

Checked, the result is x=1, y=0

My bad, wrong result description!

 
Ashes:

My bad, wrong description of the results!

Key :

https://www.mql5.com/ru/docs/basis/operations/rules

Документация по MQL5: Основы языка / Операции и выражения / Приоритеты и порядок операций
Документация по MQL5: Основы языка / Операции и выражения / Приоритеты и порядок операций
  • www.mql5.com
Основы языка / Операции и выражения / Приоритеты и порядок операций - Документация по MQL5
 
stringo:

The c++ standard does not define this place and explicitly says that it depends on the implementation. There are 2 main implementations:

1. Produce a postincrement immediately after the variable is used in the expression. (as we have done).

2. Postincrement after the whole expression is calculated.

I'm not going to argue, but it's a bit jarring when the right part is the same, but the result of calculation is different...
 

x=0; y=0; x = y++; // x = 1 !!!

x=0; y=0; y = y++; // y = 0 !!!

Did the priority of the operations manage to change ?

 
Ashes:

x=0; y=0; x = y++; // x = 1 !

How's that? x=0, y=1
 

Completely confused!

x=0; y=0; x = y++; // x = 0 ? y= 1 !!!

x=0; y=0; y = y++; // y = 0 !!!

 
Ashes:

x=0; y=0; x = y++; // x = 0 ? y= 1 !!!

Perfectly correct in all postincrement implementations without exception.

If you walk the behaviour you seem to be expecting, use preincrement. x = ++y;

 
Ashes:

Completely confused!

x=0; y=0; x = y++; // x = 0 ? y= 1 !!!

x=0; y=0; y = y++; // y = 0 !!!

Section Arithmetic operations:

Сумма величин                           i = j + 2;
Вычитание величин                       i = j - 3;
Изменение знака                         x = - x;
Умножение величин                       z = 3 * x;
Частное от деления                      i = j / 5;
Остаток от деления                      minutes = time % 60;
Добавление 1 к значению переменной      i++;
Добавление  1 к значению переменной      ++i;
Вычитание  1 от значения переменной      k--;
Вычитание  1 от значения переменной      --k;

Increment and decrement operations apply only to variables, they do not apply to constants. Prefix increment (++i) and decrement (--k) are applied to a variable just before that variable is used in an expression.

Postfix increments (i++) and decrements (k--) are applied to a variable immediately after that variable is used in an expression.

 
Rosh:

Section Arithmetic operations:

...
Postfix increments (i++) and decrements (k--) are applied to a variable immediately after that variable is used in an expression.
In both lines, postfix increment. The result (y) is different. It turns out that it depends on the context of application...
 
Ashes:
Both lines have postfix increment. The result (y) is different. It turns out that it depends on the context of application...
Can you practically justify the expression x = x++; What do you want to say? Why not use an increment without a subsequent assignment of x++; As it is usually used.