分别以值传递和引用调用两种方式编写清零函数,对学生成绩实现清零操作。
#include <string.h>
typedef struct {
char name[20];
int math;
int eng;
int db;
} Student;
void SetZero(Student &s) { memset(&s, 0, sizeof(Student)); }
void SetZero(Student *s) { memset(s, 0, sizeof(Student)); }
int main() {
Student s;
SetZero(s);
SetZero(&s);
return 0;
}