“C语言中的常变量”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第8行: | 第8行: | ||
常变量:? | 常变量:? | ||
+ | |||
+ | 示例:<syntaxhighlight lang="c"> | ||
+ | #include<stdio.h> | ||
+ | |||
+ | int g_max = 10; //全局变量 | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | int x = 0; | ||
+ | int sum = 20; | ||
+ | g_max = 100; //普通全局变量可以被赋值 | ||
+ | printf("g_max = %d \n", g_max); | ||
+ | return 0; | ||
+ | } | ||
+ | </syntaxhighlight><syntaxhighlight lang="console"> | ||
+ | g_max = 100 | ||
+ | </syntaxhighlight> |
2022年10月29日 (六) 01:31的版本
https://www.bilibili.com/video/BV1vR4y1H7MY/?p=11
用 const 关键字修饰的变量,称为常变量。// c const // c++ const
变量:可读可写;
常量:只可读不可写;
常变量:?
示例:
#include<stdio.h>
int g_max = 10; //全局变量
int main()
{
int x = 0;
int sum = 20;
g_max = 100; //普通全局变量可以被赋值
printf("g_max = %d \n", g_max);
return 0;
}
g_max = 100