int factorial(int n) {
return ( n==0 ? 1 : factorial(n-1)*n ) ;
}
对比
int factorial(int n) {
return ( n==0 ? 1 : n*factorial(n-1) ) ;
}
我想知道我更喜欢使用哪一个。 他们之间有什么区别吗? 为了获得更好的运行时间,我们是否必须考虑函数调用或变量计算的顺序的情况。
最佳答案
没有什么区别。 C 不指定 *
操作数的执行顺序,因此对于任何表达式,a * b
和 b * a
实际上是等价的a
和 b
。
关于c - 两个代码片段有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42011926/