[問題] 新手請教關於C語言參數傳遞問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
在改了主程式參數值後,執行結果有問題
餵入的資料(Input):
2、3、4、5
預期的正確結果(Expected Output):
希望可以正確印出b值
錯誤結果(Wrong Output):
編譯有warning出現
[Warning] passing arg 2 of `fun2' makes pointer from integer without a cast
程式碼(Code):(請善用置底文網頁, 記得排版)
void fun2(int a,int *b)
{
if(a<=1) return;
else
{
*b*=2;
fun2(a-1,*b);
}
}
int main()
{
int a=2,b=6;
fun2(a,&b);
printf("%d",b);
}
補充說明(Supplement):
這樣執行會印出12沒錯,但當我把主程式的a改成其他值就有問題
例如改成3,要印出24,改成4要印出48,請問是哪邊出錯了呢?
感謝各位前輩指正
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.11.172.76
推
02/15 15:13, , 1F
02/15 15:13, 1F
→
02/15 15:52, , 2F
02/15 15:52, 2F
→
02/15 15:52, , 3F
02/15 15:52, 3F
→
02/15 16:04, , 4F
02/15 16:04, 4F
→
02/15 16:41, , 5F
02/15 16:41, 5F