#include <stdio.h> //fopen函数的包
#include <stdlib.h> //exit()函数的包
#include <unistd.h>
//定义一个结构- 把struct Person当做一种数据类型
struct Person{
char *name;
int age;
int high;
};
//成员变量作为作为参数
void sum(int, int);
//结构指针作为参数
void sumPt(const struct Person *);
//结构作为参数
void sumStruct(const struct Person);
int main()
{
struct Person one = {
.name = "大王",
.age = 20,
.high = 153
};
struct Person *onePt = &one;
sum(one.age,one.high);
sumPt(onePt);
sumStruct(one);
return 0;
}
void sum(int age, int high)
{
int total = age + high;
printf("sum(%d,%d) = %d\n", age, high, total );
}
void sumPt(const struct Person *onePt)
{
int total = onePt->age + onePt->high;
printf("sum(%p) = %d\n", onePt, total );
}
void sumStruct(const struct Person one)
{
int total = one.age + one.high;
printf("sum(one) = %d\n", total );
}