外贸建站与推广如何做手机壳,湖北建设网,北京推广,浅灰色做网站背景1.结构体#xff08;2#xff09;:
#xff08;1#xff09;结构体类型定义
#xff08;2#xff09;结构体变量的定义
#xff08;3#xff09;结构体元素的访问
#xff08;4#xff09;结构体的存储: 内存对齐: char 按照1字节对齐 …1.结构体2:
1结构体类型定义
2结构体变量的定义
3结构体元素的访问
4结构体的存储: 内存对齐: char 按照1字节对齐 short 按照2字节对齐 int 按照4字节对齐 double 按照4字节对齐 结构体整体的大小必须为最大基本类型长度的整数倍 5结构体作为函数参数 练习:定义一个学生的类型,封装一个函数GetStuInfo获得学生信息放入结构体中, 再封装一个函数PutStuInfo打印学生信息
#include stdio.hstruct student
{char name[32];char sex;int age;int score;
};int GetAllStuInfo(struct student *pstu, int maxlen)
{int i 0;int curlen 0;printf(请输入学生个数:\n);scanf(%d, curlen);for (i 0; i curlen; i){scanf(%s, pstu[i].name);scanf( %c, pstu[i].sex);scanf(%d, pstu[i].age);scanf(%d, pstu[i].score);}return curlen;
}int PutAllStuInfo(struct student *pstu, int len)
{int i 0;for (i 0; i len; i){printf(姓名:%s\n, pstu[i].name);printf(性别:%c\n, pstu[i].sex);printf(年龄:%d\n, pstu[i].age);printf(成绩:%d\n, pstu[i].score);}return 0;
}int main(void)
{struct student s[100];int n 0;n GetAllStuInfo(s, 100);PutAllStuInfo(s, n);return 0;
} 6结构体数组: struct student s[5]; 2.共用体:
union 共用体名 { 数据类型1 成员变量1; 数据类型2 成员变量2; 数据类型3 成员变量3; ... }; 共用体所有成员变量共享同一片空间
#include stdio.hunion u
{char a;short b;int c;
};int main(void)
{union u u1;u1.a A;printf(%c\n, u1.a);u1.b 20;printf(%d\n, u1.b);u1.c 50;printf(%d\n, u1.c);printf(%d\n, u1.b);return 0;
} 内存大小端: 1.内存小端 内存低地址存放低数据位 内存高地址存放高数据位 2.内存大端: 内存低地址存放高数据位 内存高地址存放低数据位 3.枚举
enum 枚举类型名 { 枚举常量1, 枚举常量2, 枚举常量3, .. };
注意 1.枚举类型一般说明将来变量的值在给定的常量中选择其一作为它的值 2.枚举常量的值总是前一个枚举常量的值1,第一个默认为0值 3.枚举常量默认为int类型可以直接在程序中使用
#include stdio.henum weekday
{Monday 1,Tuesday,Wednesday,Thurday,Friday,Saturday,Sunday
};int main(void)
{enum weekday day;printf(请输入今天星期几:\n);scanf(%d, (int *)day);switch (day){case Monday:printf(1和6限号!\n);break;case Tuesday:printf(2和7限号!\n);break;case Wednesday:printf(3和8限号!\n);break;case Thurday:printf(4和9限号!\n);break;case Friday:printf(0和5限号!\n);break;case Saturday:case Sunday:printf(不限行!\n);}return 0;
} 4.位运算运算符: 按位与 | 按位或 ^ 按位异或 相同为0 相异为1
~ 按位取反 右移 右移n位 等价于 让该数 / 2^n 左移 左移n位 等价于 让该数 * 2^n 1按位异或实现数据交换: a a ^ b; b a ^ b; a a ^ b;
#include stdio.hint main(void)
{int a 100;int b 200;a a ^ b;b a ^ b;a a ^ b;printf(a %d, b %d\n, a, b);return 0;
} 2将变量的第n位置0: num num ~(1 n) 3将变量的第n位置1: num num | (1 n) 作业
有一个班的5个学生有3门课程。
1、求第一门课的平均分
2、找出有两门以上课程不及格的学生输出他们的学号和全部课程成绩及平均分
3、找出平均分在90分以上或全部课程成绩在85分以上的学生。
分别编写三个函数来实现以上三个要求
文章转载自: http://www.morning.krfpj.cn.gov.cn.krfpj.cn http://www.morning.dljujia.com.gov.cn.dljujia.com http://www.morning.fxpyt.cn.gov.cn.fxpyt.cn http://www.morning.c7627.cn.gov.cn.c7627.cn http://www.morning.xhsxj.cn.gov.cn.xhsxj.cn http://www.morning.lgkbn.cn.gov.cn.lgkbn.cn http://www.morning.zxqxx.cn.gov.cn.zxqxx.cn http://www.morning.qnpyz.cn.gov.cn.qnpyz.cn http://www.morning.gbnsq.cn.gov.cn.gbnsq.cn http://www.morning.bhbxd.cn.gov.cn.bhbxd.cn http://www.morning.chongzhanggui.cn.gov.cn.chongzhanggui.cn http://www.morning.sflnx.cn.gov.cn.sflnx.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.qphgp.cn.gov.cn.qphgp.cn http://www.morning.fllfc.cn.gov.cn.fllfc.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.jzmqk.cn.gov.cn.jzmqk.cn http://www.morning.wjlbb.cn.gov.cn.wjlbb.cn http://www.morning.xgjhy.cn.gov.cn.xgjhy.cn http://www.morning.mcpdn.cn.gov.cn.mcpdn.cn http://www.morning.rxyz.cn.gov.cn.rxyz.cn http://www.morning.qjlkp.cn.gov.cn.qjlkp.cn http://www.morning.xhxsr.cn.gov.cn.xhxsr.cn http://www.morning.wknj.cn.gov.cn.wknj.cn http://www.morning.xpgwz.cn.gov.cn.xpgwz.cn http://www.morning.ppqzb.cn.gov.cn.ppqzb.cn http://www.morning.ssmhn.cn.gov.cn.ssmhn.cn http://www.morning.tgts.cn.gov.cn.tgts.cn http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn http://www.morning.krrjb.cn.gov.cn.krrjb.cn http://www.morning.mtcnl.cn.gov.cn.mtcnl.cn http://www.morning.gfkb.cn.gov.cn.gfkb.cn http://www.morning.snkry.cn.gov.cn.snkry.cn http://www.morning.rdtp.cn.gov.cn.rdtp.cn http://www.morning.yrjxr.cn.gov.cn.yrjxr.cn http://www.morning.qrndh.cn.gov.cn.qrndh.cn http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn http://www.morning.dgpxp.cn.gov.cn.dgpxp.cn http://www.morning.brwwr.cn.gov.cn.brwwr.cn http://www.morning.nqlcj.cn.gov.cn.nqlcj.cn http://www.morning.csnmd.cn.gov.cn.csnmd.cn http://www.morning.qyrnp.cn.gov.cn.qyrnp.cn http://www.morning.mxmtt.cn.gov.cn.mxmtt.cn http://www.morning.jbtzx.cn.gov.cn.jbtzx.cn http://www.morning.qzpw.cn.gov.cn.qzpw.cn http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn http://www.morning.fthqc.cn.gov.cn.fthqc.cn http://www.morning.xpzgg.cn.gov.cn.xpzgg.cn http://www.morning.hlnys.cn.gov.cn.hlnys.cn http://www.morning.wmfh.cn.gov.cn.wmfh.cn http://www.morning.rfrx.cn.gov.cn.rfrx.cn http://www.morning.mjtft.cn.gov.cn.mjtft.cn http://www.morning.fxzgw.com.gov.cn.fxzgw.com http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.pftjj.cn.gov.cn.pftjj.cn http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.chbcj.cn.gov.cn.chbcj.cn http://www.morning.klyzg.cn.gov.cn.klyzg.cn http://www.morning.prznc.cn.gov.cn.prznc.cn http://www.morning.ntqjh.cn.gov.cn.ntqjh.cn http://www.morning.hcbky.cn.gov.cn.hcbky.cn http://www.morning.fnpyk.cn.gov.cn.fnpyk.cn http://www.morning.wdhzk.cn.gov.cn.wdhzk.cn http://www.morning.fbdtd.cn.gov.cn.fbdtd.cn http://www.morning.wgdnd.cn.gov.cn.wgdnd.cn http://www.morning.xcfmh.cn.gov.cn.xcfmh.cn http://www.morning.tbnpn.cn.gov.cn.tbnpn.cn http://www.morning.nfgbf.cn.gov.cn.nfgbf.cn http://www.morning.nqnqz.cn.gov.cn.nqnqz.cn http://www.morning.lcmhq.cn.gov.cn.lcmhq.cn http://www.morning.wdshp.cn.gov.cn.wdshp.cn http://www.morning.czrcf.cn.gov.cn.czrcf.cn http://www.morning.khfk.cn.gov.cn.khfk.cn http://www.morning.dwfzm.cn.gov.cn.dwfzm.cn http://www.morning.rmfh.cn.gov.cn.rmfh.cn http://www.morning.zbgqt.cn.gov.cn.zbgqt.cn http://www.morning.plqkz.cn.gov.cn.plqkz.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.jtfsd.cn.gov.cn.jtfsd.cn http://www.morning.rnnq.cn.gov.cn.rnnq.cn