低調簡單
2009年4月23日 星期四
function回傳指標範例
#include
int *
func(int x,int y)
{
int *z;
z=malloc(sizeof(int));
*z=x+y;
return z;
}
int main()
{
int buf=5;
int *ans=&buf;
int x=2,y=9;
printf("ans=%d\n",*ans);
ans
=func(x,y);
printf("return pointer : ans= %d\n",*ans);
free(ans);
}
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言