2014-10-10 35 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); 
    }