struct結構與struct當作函數參數傳遞 by reference

#include
#include
typedef struct {
char color[10];
double radius;
} Ball;

void foo(Ball*);

int main(void) {
Ball ball = {"red", 5.0};

foo(&ball);
printf("ball: %s,\t%.2f\n", ball.color, ball.radius);
system("pause");
return 0;
}

void foo(Ball *ball) { // ball 成員值被複製過來
ball->radius = 100.0;
}

沒有留言: