c语言小问题,求解答

定义一个结构体类型 student,包含三个变量,分别存储自 己的姓名、性别、学号 定义一个函数,实现交换两个 student 结构体内容的 功能。 定义 2 个 student 结构体变量 stu1,stu2 分别输入两个结构体变量的值 分别打印 stu1, stu2 中的内容,之后利用自己定义的函数 交换 stu1, stu2 中的内容,再分别打印 stu1,stu2

#include <stdio.h>
#include <string.h>

typedef struct Student
{
    char name[20];
    int gender;
    int id;
} Student;

void swap(Student *a, Student *b)
{
    char tmp[20];
    strcpy(tmp, a->name);
    strcpy(a->name, b->name);
    strcpy(b->name, tmp);

    int tmp_id = a->id;
    a->id = b->id;
    b->id = tmp_id;

    int tmp_gender = a->gender;
    a->gender = b->gender;
    b->gender = tmp_gender;
}

void print(Student s, char *title)
{
    printf("%s:  name: %s, gender: %s, id: %d\n", title, s.name, ((s.gender == 0) ? "male" : "female"), s.id);
}

int main()
{
    Student s1 = {"aaa", 0, 123};
    Student s2 = {"bbb", 1, 234};
    print(s1, "s1");
    print(s2, "s2");
    swap(&s1, &s2);
    print(s1, "s1");
    print(s2, "s2");
}

/* output:
    s1:  name: aaa, gender: male, id: 123
    s2:  name: bbb, gender: female, id: 234
    s1:  name: bbb, gender: female, id: 234
    s2:  name: aaa, gender: male, id: 123
*/