共 9 篇文章 |
|
当然,指针本身和它指向的数据都有可能是只读的,下面的两种写法能够做到这一点:复制纯文本复制const int * const p4;int const * const p5;const int * const p4;int const * const p5;const 和指针结合的写法多少有点让初学者摸不着头脑,大家可以这样来记忆:const 离变量名近就是用来修饰指针变量的,离变量名远就是用来修饰指针指向的数... 阅67 转0 评0 公众公开 16-12-08 17:33 |
阅104 转2 评0 公众公开 16-12-08 17:32 |
请看下面的位域 bs:复制纯文本复制#include int main(){ struct bs{ unsigned m: 12; unsigned char ch: 4; unsigned p: 4; }; printf(''%d\n'', sizeof(struct bs)); return 0;}#include int main(){ struct bs{ unsigned m: 12; unsigned char ch: 4; unsigned p: 4; }; printf(''%d\n'', sizeof(struct ... 阅87 转0 评0 公众公开 16-12-08 17:31 |
0000 0000 -- 0000 0000 -- 0000 0000 -- 0000 1001 (9 在内存中的存储)& 0000 0000 -- 0000 0000 -- 0000 0000 -- 0000 0101 (5 在内存中的存储)----------------------------------------------------------------------------------- 0000 0000 -- 0000 0000 -- 0000 0000 -- 0000 0001 (1 在内存中的存储)也就是说,按位与... 阅61 转0 评0 公众公开 16-12-08 17:31 |
阅55 转0 评0 公众公开 16-12-08 17:28 |
复制纯文本复制#include int main(){ struct{ char *name; //姓名 int num; //学号 int age; //年龄 char group; //所在小组 float score; //成绩 } stu1 = { ''Tom'', 12, 18, ''A'', 136.5 }, *pstu = &stu1; //读取结构体成员的值 printf(''%s的学号是%d,年龄是%d,在%c组,今年的成绩是%.1f... 阅125 转0 评0 公众公开 16-12-08 17:28 |
定义结构体数组和定义结构体变量的方式类似,请看下面的例子:复制纯文本复制struct stu{ char *name; //姓名 int num; //学号 int age; //年龄 char group; //所在小组 float score; //成绩}class[5];struct stu{ char *name; //姓名 int num; //学号 int age; //年龄 char group; //所在小组 float score; //成绩}class[5];表示一个班级有5... 阅111 转0 评0 公众公开 16-12-08 17:27 |
C语言typedef:给类型起一个别名C语言允许为一个数据类型起一个新的别名,就像给人起“绰号”一样。又如,为结构体类型定义别名:复制纯文本复制typedef struct stu{ char name[20]; int age; char sex;} STU;typedef struct stu{ char name[20]; int age; char sex;} STU;STU 是 struct stu 的别名,可以用 STU 定义结构体变量:typedef int (... 阅84 转0 评0 公众公开 16-12-08 17:27 |
你也可以在定义结构体的同时定义结构体变量:复制纯文本复制struct stu{ char *name; //姓名 int num; //学号 int age; //年龄 char group; //所在学习小组 float score; //成绩} stu1, stu2;struct stu{ char *name; //姓名 int num; //学号 int age; //年龄 char group; //所在学习小组 float score; //成绩} stu1, stu2;将变量放在结构体定... 阅26 转0 评0 公众公开 16-12-08 17:20 |