1.函数的值传递,无法通过调用函数,来修改函数的实参。
2.被调用函数需要提供更多的“返回值”,给调用函数
3. 指针能极大的提高效率
#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; //1.函数的值传递,无法通过调用函数,来修改函数的实参。 //2.被调用函数需要提供更多的“返回值”,给调用函数 //3. 指针能极大的提高效率 struct _hero_stat{ int blood;//英雄的血量 int power;//英雄的攻击率 int level;//英雄的等级 char name[64];//英雄的名字 char details[1024];//状态描述 }; //使用结构体 struct _hero_stat upgrade1(struct _hero_stat hero, int type){ switch (type) { case 1://攻击型英雄 hero.blood += 10; hero.power += 20; hero.level++; break; case 2://防御型英雄 hero.blood += 20; hero.power += 10; hero.level++; break; default: break; } return (hero); } //使用指针实现 void upgrade2(struct _hero_stat *hero, int type
12345678910111213141516171819202122232425262728293031323334