[問題] 函數回傳值不正確

看板C_and_CPP (C/C++)作者 (tim845487)時間15年前 (2011/01/06 21:02), 編輯推噓2(205)
留言7則, 6人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, Gcc, Linux, ...) DEV C++ 額外使用到的庫(Library Used) (Ex: OpenGL, ...) 問題(Question): 不管怎麼寫我的函數 回傳的值都不正確 像下面這個相加的函數 預期回傳3+4=7 可是程式跑出來卻是16384 我的程式問題到底在哪呢? 程式碼(Code): (請善用置底文標色功能) #include <stdio.h> #include <stdlib.h> #include <math.h> int add(int a,int b) { int c; c==a+b; return (c); } main() { int x,y; x==3; y==4; printf("%d",add(x,y)); system("PAUSE"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.101.199

01/06 21:04, , 1F
==
01/06 21:04, 1F

01/06 21:07, , 2F
你應該課本沒看熟…
01/06 21:07, 2F

01/06 21:07, , 3F
1.只要一個等於 2. int c = 0;
01/06 21:07, 3F

01/06 21:12, , 4F
謝謝 我知道了:x=3,y=4,c=0
01/06 21:12, 4F

01/06 21:12, , 5F
c=a+b
01/06 21:12, 5F

01/06 21:28, , 6F
XDD
01/06 21:28, 6F

01/07 07:28, , 7F
這排版...
01/07 07:28, 7F
文章代碼(AID): #1D9RrilL (C_and_CPP)
文章代碼(AID): #1D9RrilL (C_and_CPP)