/*C語言 將結構的位址傳遞到函數裡*/
#include<stdio.h>
#include<stdlib.h>
struct data
{
char name[10];
int score;
};
void function(struct data*, struct data*);
int main(void)
{
struct data student1 = { "A", 87 };
struct data student2 = { "B", 78 };
function(&student1, &student2);
printf("Student1 name:%s score:%d\n",
student1.name, student1.score);
printf("Student2 name:%s score:%d\n",
student2.name, student2.score);
system("pause");
return 0;
}
void function(struct data* i, struct data* j)
{
struct data k;
k = *i;
*i = *j;
*j = k;
}
結果為:
文章標籤
全站熱搜
留言列表