What should return this code segment? 16 16 16 right?
int main(int argc,char *argv[]) { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f1+=a+=2.5; printf("%d %d %d\n",a,*f1,*f2); return 0; }
strange, he returns 8 8 8 to me ????: - (
For a real understanding of the problem here, try the comp.lang.c FAQ in the sequence point article .
*f2+=*f1+=a+=2.5;
Same Old Undefined Behavior.
undefined, a . , , .
a
This behavior is undefined according to specification 6.5 / 2, since you modify an object more than once between a point in a sequence:
Between the previous and the next point in the sequence, the object must have a stored value, changed to most often by evaluating the expression. In addition, the previous value should only be read to determine the value to be saved.
It seems to be translated into
*f2 += 2; *f1 += 2; a += 2.5;
and that is +=not as transitive as =.
+=
=
Source: https://habr.com/ru/post/1769356/More articles:tsql: Is the TSQL connection update conversion access request correct? - tsqlHow to detect in Safari if the application is installed - safariCovering dots on a table - mathApplication.LoadComponent заставляет замораживать приложение при выключении - visual-studio-2008accented letters are not displayed correctly on the server, even if the encoding is correct - htmlField refactoring properties - c #EF 4.0 POCO magic doesn't work - no changes detected - entity-frameworkПростая проблема с машиной - vhdlДля чего нужен файл конфигурации .NET XML? - .netUsing a dynamic URL to add an image using XSL: FO - xmlAll Articles