答案是90,但我没有得到解决方案?有人请帮忙 [英] It's answer is 90, but I didn't get the solution? Anyone please help

查看:64
本文介绍了答案是90,但我没有得到解决方案?有人请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   stdio.h  >  
int main(){
int a [] = { 10 20 30 40 };
int i = 3 ,x;
x = 1 * a [ - i] + 2 * a [ - i] + 3 * a [ - i];
printf( %d,x);
return 0 ;
}





我的尝试:



我在在线IDE工具上尝试了它并获得了答案90,但没有得到解决方案

解决方案

你处于灰色区域。代码建议

 x =  1  * a [i-  1 ] + 2 * a [i-  2 ] + 3 * a [i-  3 ]; 



但你没有保证,因为C编译器是一个重写器。

这意味着编译器可以自由重写这段代码更喜欢它。更糟糕的是,结果可能会随着另一个编译器而改变。



了解代码转换方式的唯一方法是在汇编级别使用调试器来查看它是如何编译的翻译


#include<stdio.h>
int main(){
    int a[]={10,20,30,40};
    int i=3,x;
    x=1*a[--i]+2*a[--i]+3*a[--i];
    printf("%d",x);
    return 0;
}



What I have tried:

I have tried it on Online IDE tools and getting the answer 90, but didnot get the solution

解决方案

You are in gray zone. the code suggest

x=1*a[i-1]+2*a[i-2]+3*a[i-3];


But you have no guaranty of that because C compiler is a rewriter.
This mean that the compiler is free to rewrite this code the way it prefer. Even worst, the result may change with another compiler.

The only way to know how the code is translated is to use a debugger at assembly level to see how it is translated.


这篇关于答案是90,但我没有得到解决方案?有人请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆