2014-10-10 29 views
0

前面调用带负号的函数的结果是什么?是否将返回值转为负值?C:带有负号的重复函数调用

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 
} 

回答

1

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

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

这是如何在上下文中使用的更难以猜测,因为你不知道在你的问题中提供很多背景。

1

亚...返回值存储为-五个变量thisScore值..

试试这个代码...这可能会清除您的疑问

#include<stdio.h> 

int fun(void) 
    { 
    return 20; 
    } 

    main() 
    { 
    int a=- fun(); 
    printf("%d\n",a); 
    }