D语言运算符优先级

import std.stdio;

int main(string[] args) { 
   int a = 20; 
   int b = 10; 
   int c = 15; 
   int d = 5; 
   int e;

   e = (a + b) * c / d;      // ( 30 * 15 ) / 5 
   writefln("Value of (a + b) * c / d is : %d/n",  e ); 

   e = ((a + b) * c) / d;    // (30 * 15 ) / 5 
   writefln("Value of ((a + b) * c) / d is  : %d/n" ,  e );  

   e = (a + b) * (c / d);   // (30) * (15/5) 
   writefln("Value of (a + b) * (c / d) is  : %d/n",  e );

   e = a + (b * c) / d;     //  20 + (150/5) 
   writefln("Value of a + (b * c) / d is  : %d/n" ,  e ); 

   return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/265965.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论