萌新初来乍到,请多指教
变量x,y为double类型,变量a,b为int类型,数学式6*a*b/(7*x*y)的表达式为什么是 6/x*a*b/7/y
程序代码:
#include <stdio.h> int main(int argc, char *argv[]) { int a, b; //add volatile to mask gcc overdoing optimization volatile double x, y; double formula; #define critical_section_in ((int *)&a)[0] = 10; ((int *)&a)[1] = 20; *(double *)&((int *)&a)[2] = 1.25; *(double *)&((int *)&a)[4] = 12.17; #define critical_section_out //attention: while closed print_on gcc optimized the statment (7.0 * x * y) #define PRINT_ON #ifdef PRINT_ON printf("a = %p\n", &a); printf("a = %d\n", a); printf("b = %d\n", b); printf("(a->x) = %p-----", &((int *)&a)[2]); printf("x = %p\n", &x); printf("x = %lf\n", x); printf("y = %lf\n", y); #endif formula = 6 * a * b; formula = formula / (7.0 * x * y); printf("f = %.2lf\n", formula); return 0; }
output sample:
a = 0x7ffee15347f8
a = 10
b = 20
(a->x) = 0x7ffee1534800-----x = 0x7ffee1534800
x = 1.250000
y = 12.170000
f = 11.27
[此贴子已经被作者于2021-10-12 13:53编辑过]