Re: [問題] 指向函式的指標語法..

看板C_and_CPP (C/C++)作者 (小惡魔)時間16年前 (2010/02/10 16:11), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串2/2 (看更多)
※ 引述《oit73 (我需要"激勵")》之銘言: : 以下是我練習--指向函式的指標語法 : 目的→x,y值 互換 : 想請教下面是哪出問題...x,y一直沒辦法互換 : (一直沒辦法學好指標耶..) : <<程式開始>> : #include <stdio.h> : #include <stdlib.h> : float call(float x, float y , float(*ptr)(float,float)){ : return (*ptr)(x,y); : } : float fun(float x, float y){ : float temp; : temp = x; : x = y; : y = temp; : return x,y; : } : int main(){ : float x,y; : printf("x = ");scanf("%f", &x); : printf("y = ");scanf("%f", &y); : printf("\n\n"); : call(x,y,fun); : printf("對調後, x = %f\n", x); : printf(" , y = %f", y); : system("pause"); : } float call(float *x, float *y , float(*ptr)(float *,float *)){ return (*ptr)(x, y); } float fun(float *x, float *y){ float temp; temp = *x; *x = *y; *y = temp; } int main() { float x,y; printf("x = ");scanf("%f", &x); printf("y = ");scanf("%f", &y); printf("\n\n"); call(&x,&y,fun); printf("對調後, x = %.1f\n", x); printf(" , y = %.1f", y); system("pause"); } 感謝推文指正,果然沒有 call by address,一直都是 call by value -- PHP MVC CodeIgniter 繁體中文手冊: http://tinyurl.com/mduyv8 PHP MVC CodeIgniter 繁體中文討論區:http://tinyurl.com/yayzoz8 PHP MVC CodeIgniter 中文官方網站: http://tinyurl.com/yatds8n Appleboy Blog 電腦技術: http://blog.Wu-Boy.com -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.107.202

02/10 18:43, , 1F
都是 call by value 喔
02/10 18:43, 1F

02/10 19:03, , 2F
同樓上l大, 順便推一下精華去: 3->7->9 :)
02/10 19:03, 2F

02/11 01:14, , 3F
沒有call by address吧?>
02/11 01:14, 3F
※ 編輯: appleboy46 來自: 140.123.107.202 (02/11 12:17)

02/11 12:17, , 4F
感謝推文指導
02/11 12:17, 4F
文章代碼(AID): #1BSceqtk (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1BSceqtk (C_and_CPP)