“C语言中的枚举常量”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) (建立内容为“https://www.bilibili.com/video/BV1vR4y1H7MY/?p=12”的新页面) |
Jihongchang(讨论 | 贡献) |
||
| 第1行: | 第1行: | ||
https://www.bilibili.com/video/BV1vR4y1H7MY/?p=12 | https://www.bilibili.com/video/BV1vR4y1H7MY/?p=12 | ||
| + | |||
| + | 以星期为例:<syntaxhighlight lang="c"> | ||
| + | #include<stdio.h> | ||
| + | // mon = 1, tue = 2, wed = 3, thu = 4, fri = 5, sat = 6, sun = 7 | ||
| + | int main() | ||
| + | { | ||
| + | int wx; // 1 2 3 4 5 6 7 | ||
| + | wx = 1; | ||
| + | wx = 7; | ||
| + | wx = 9; //实际没有9对应周几 | ||
| + | printf("%d \n", wx); | ||
| + | return 0; | ||
| + | } | ||
| + | </syntaxhighlight>如上,有时候我们需要限制取值的范围。 | ||
2022年10月29日 (六) 14:22的版本
https://www.bilibili.com/video/BV1vR4y1H7MY/?p=12
以星期为例:
#include<stdio.h>
// mon = 1, tue = 2, wed = 3, thu = 4, fri = 5, sat = 6, sun = 7
int main()
{
int wx; // 1 2 3 4 5 6 7
wx = 1;
wx = 7;
wx = 9; //实际没有9对应周几
printf("%d \n", wx);
return 0;
}
如上,有时候我们需要限制取值的范围。