C:带负号的递归函数调用

C:带负号的递归函数调用,c,recursion,C,Recursion,如果函数前面有一个负号,调用该函数的结果是什么?是否将返回值转换为负值 int someFunction(int newBoard[9], int aValue) { for(i = 0; i < 9; ++i) { if(newBoard[i] == 0) { newBoard[i] = player; int thisScore = -someFunction(newBoard, aValue*-1);

如果函数前面有一个负号,调用该函数的结果是什么?是否将返回值转换为负值

int someFunction(int newBoard[9], int aValue) {

    for(i = 0; i < 9; ++i) {
        if(newBoard[i] == 0) {
            newBoard[i] = player;
            int thisScore = -someFunction(newBoard, aValue*-1); 
            // why this function being called with a negative sign?   Is to turn the return value into negative?
        }
    }
  return someValue
}
int-someFunction(int-newBoard[9],int-aValue){
对于(i=0;i<9;++i){
if(新板[i]==0){
新手[i]=玩家;
int thiscore=-someFunction(newBoard,aValue*-1);
//为什么用负号调用此函数?是为了将返回值变为负数?
}
}
返回某个值
}

是的,这是正确的,因为someFunction返回一个整数,在前面加一个“-”将否定结果

e.g. int n = 1;
     printf( "%d", -n );
     ...
     -1

这在你的上下文中是如何使用的更难猜测,因为你没有在你的问题中提供太多的上下文。

ya。。。返回值存储为变量
thisScore
中的
-
ve值

试试这个代码……它可能会消除你的疑虑

 #include<stdio.h>

 int fun(void)
  {
   return 20;
  }

  main()
  {
    int a=- fun();
    printf("%d\n",a);
  }
#包括
int fun(无效)
{
返回20;
}
main()
{
int a=-fun();
printf(“%d\n”,a);
}