云计算百科
云计算领域专业知识百科平台

补:变量与常量

一.区别

两者都是用来储存数据的容器,但变量的值可以改变,而常量的值一但设定无法再次修改

二.变量(可改值)

1.类型

date_type name
//date_type 数据类型
//name 数据名

2.命名

(1)最好有意义
(2)只能由字母(区分大小写),数字,下划线(“_”)组成
(3)不能以数字开头
(4)长度不能超过63个字符
(5)变量名不能使用关键字
(6)区分大小写(int abc != int Abc)
(7)变量最好初始化

3.初始化与赋值的区分

第一次为初始化,第二次为赋值

date_type name = 1;//初始化
name = 2;//赋值

4.变量的分类

全局变量与局部变量
(1)全局变量(放在函数外,范围广)
作用域:从定义位置开始,到整个源文件末尾都可使用(整个程序)
【若其他程序想用,可通过extern声明】

生命周期:程序启动到程序结束
【存放在静态存储区/数据段】

初始值:若未初始化,系统会自动初始化为0
【或\\0,NULL】

注:过多的使用会使模块间耦合度过高,调试困难,谨慎使用
【耦合度指代码不够独立,代码需高内聚,低耦合】

(2)局部变量(放在函数内,精度高)
作用域:仅限于定义它的函数或代码块内部,外部无法使用

生命周期:进入函数/代码时创建到退出时销毁
【存在内存的栈区】

初始值:若未初始化,值默认为垃圾值(不确定的随机数),建议初始化

优先级:局部优先于全局

5.变量本质

创建变量的本质:在内存上申请空间
变量类型的意义:申请空间大小

6.存储

#mermaid-svg-ityn30DwLPCo5c3f{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-ityn30DwLPCo5c3f .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-ityn30DwLPCo5c3f .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-ityn30DwLPCo5c3f .error-icon{fill:#552222;}#mermaid-svg-ityn30DwLPCo5c3f .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ityn30DwLPCo5c3f .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-ityn30DwLPCo5c3f .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ityn30DwLPCo5c3f .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ityn30DwLPCo5c3f .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-ityn30DwLPCo5c3f .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ityn30DwLPCo5c3f .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ityn30DwLPCo5c3f .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ityn30DwLPCo5c3f .marker.cross{stroke:#333333;}#mermaid-svg-ityn30DwLPCo5c3f svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ityn30DwLPCo5c3f p{margin:0;}#mermaid-svg-ityn30DwLPCo5c3f .edge{stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .section–1 rect,#mermaid-svg-ityn30DwLPCo5c3f .section–1 path,#mermaid-svg-ityn30DwLPCo5c3f .section–1 circle,#mermaid-svg-ityn30DwLPCo5c3f .section–1 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section–1 text{fill:#ffffff;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth–1{stroke-width:17;}#mermaid-svg-ityn30DwLPCo5c3f .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-0 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-0 path,#mermaid-svg-ityn30DwLPCo5c3f .section-0 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-0 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-ityn30DwLPCo5c3f .section-0 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-0{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-0{stroke-width:14;}#mermaid-svg-ityn30DwLPCo5c3f .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-1 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-1 path,#mermaid-svg-ityn30DwLPCo5c3f .section-1 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-1 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-1 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-1{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-1{stroke-width:11;}#mermaid-svg-ityn30DwLPCo5c3f .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-2 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-2 path,#mermaid-svg-ityn30DwLPCo5c3f .section-2 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-2 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-2 text{fill:#ffffff;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-2{stroke-width:8;}#mermaid-svg-ityn30DwLPCo5c3f .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-3 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-3 path,#mermaid-svg-ityn30DwLPCo5c3f .section-3 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-3 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-3 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-3{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-3{stroke-width:5;}#mermaid-svg-ityn30DwLPCo5c3f .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-4 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-4 path,#mermaid-svg-ityn30DwLPCo5c3f .section-4 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-4 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-4 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-4{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-4{stroke-width:2;}#mermaid-svg-ityn30DwLPCo5c3f .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-5 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-5 path,#mermaid-svg-ityn30DwLPCo5c3f .section-5 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-5 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-5 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-5{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-5{stroke-width:-1;}#mermaid-svg-ityn30DwLPCo5c3f .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-6 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-6 path,#mermaid-svg-ityn30DwLPCo5c3f .section-6 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-6 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-6 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-6{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-6{stroke-width:-4;}#mermaid-svg-ityn30DwLPCo5c3f .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-7 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-7 path,#mermaid-svg-ityn30DwLPCo5c3f .section-7 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-7 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-7 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-7{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-7{stroke-width:-7;}#mermaid-svg-ityn30DwLPCo5c3f .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-8 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-8 path,#mermaid-svg-ityn30DwLPCo5c3f .section-8 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-8 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-8 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-8{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-8{stroke-width:-10;}#mermaid-svg-ityn30DwLPCo5c3f .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-9 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-9 path,#mermaid-svg-ityn30DwLPCo5c3f .section-9 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-9 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-9 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-9{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-9{stroke-width:-13;}#mermaid-svg-ityn30DwLPCo5c3f .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-10 rect,#mermaid-svg-ityn30DwLPCo5c3f .section-10 path,#mermaid-svg-ityn30DwLPCo5c3f .section-10 circle,#mermaid-svg-ityn30DwLPCo5c3f .section-10 polygon,#mermaid-svg-ityn30DwLPCo5c3f .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-10 text{fill:black;}#mermaid-svg-ityn30DwLPCo5c3f .node-icon-10{font-size:40px;color:black;}#mermaid-svg-ityn30DwLPCo5c3f .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .edge-depth-10{stroke-width:-16;}#mermaid-svg-ityn30DwLPCo5c3f .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-ityn30DwLPCo5c3f .disabled,#mermaid-svg-ityn30DwLPCo5c3f .disabled circle,#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:lightgray;}#mermaid-svg-ityn30DwLPCo5c3f .disabled text{fill:#efefef;}#mermaid-svg-ityn30DwLPCo5c3f .section-root rect,#mermaid-svg-ityn30DwLPCo5c3f .section-root path,#mermaid-svg-ityn30DwLPCo5c3f .section-root circle,#mermaid-svg-ityn30DwLPCo5c3f .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-ityn30DwLPCo5c3f .section-root text{fill:#ffffff;}#mermaid-svg-ityn30DwLPCo5c3f .section-root span{color:#ffffff;}#mermaid-svg-ityn30DwLPCo5c3f .section-2 span{color:#ffffff;}#mermaid-svg-ityn30DwLPCo5c3f .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-ityn30DwLPCo5c3f .edge{fill:none;}#mermaid-svg-ityn30DwLPCo5c3f .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-ityn30DwLPCo5c3f :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

内存(c/c++需关注的三区)

栈区

局部变量,函数参数

默认不给初始值

堆区

动态内存管理,maloc,calloc,realloc,free

静态口

全局变量,静态变量

默认初始值为0

初始值给不给取决于效率

三.常量

1.分类

#mermaid-svg-EtzPRgwVkpPRu7I4{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-EtzPRgwVkpPRu7I4 .error-icon{fill:#552222;}#mermaid-svg-EtzPRgwVkpPRu7I4 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-EtzPRgwVkpPRu7I4 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-EtzPRgwVkpPRu7I4 .marker.cross{stroke:#333333;}#mermaid-svg-EtzPRgwVkpPRu7I4 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-EtzPRgwVkpPRu7I4 p{margin:0;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge{stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section–1 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section–1 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section–1 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section–1 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section–1 text{fill:#ffffff;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth–1{stroke-width:17;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-0 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-0 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-0 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-0 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-0 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-0{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-0{stroke-width:14;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-1 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-1 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-1 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-1 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-1 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-1{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-1{stroke-width:11;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 text{fill:#ffffff;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-2{stroke-width:8;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-3 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-3 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-3 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-3 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-3 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-3{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-3{stroke-width:5;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-4 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-4 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-4 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-4 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-4 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-4{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-4{stroke-width:2;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-5 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-5 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-5 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-5 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-5 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-5{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-5{stroke-width:-1;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-6 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-6 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-6 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-6 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-6 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-6{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-6{stroke-width:-4;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-7 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-7 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-7 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-7 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-7 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-7{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-7{stroke-width:-7;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-8 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-8 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-8 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-8 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-8 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-8{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-8{stroke-width:-10;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-9 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-9 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-9 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-9 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-9 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-9{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-9{stroke-width:-13;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-10 rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-10 path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-10 circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-10 polygon,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-10 text{fill:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .node-icon-10{font-size:40px;color:black;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge-depth-10{stroke-width:-16;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:lightgray;}#mermaid-svg-EtzPRgwVkpPRu7I4 .disabled text{fill:#efefef;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-root rect,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-root path,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-root circle,#mermaid-svg-EtzPRgwVkpPRu7I4 .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-root text{fill:#ffffff;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-root span{color:#ffffff;}#mermaid-svg-EtzPRgwVkpPRu7I4 .section-2 span{color:#ffffff;}#mermaid-svg-EtzPRgwVkpPRu7I4 .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-EtzPRgwVkpPRu7I4 .edge{fill:none;}#mermaid-svg-EtzPRgwVkpPRu7I4 .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-EtzPRgwVkpPRu7I4 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

常量

字面常量

符号常量

const常量

枚举常量

2.字面常量

(1)字符常量:
‘a’,‘b’,‘c’
(2)整型常量:
十进制:123,-123,0
八进制:037(以0开头)【=31】
十六进制:0x1F(以0x/0X开头)【=31】
(3)后缀:
u/U:unsigned 无符号整型
l/L:long 长整型(可与u/U组合)
ll/LL:long long 长长整型(可与u/U组合)
(4)浮点型:
无后缀
3.14【double】
有后缀
3.14f【float】
3.14L【long double】
1.2e3【科学计数法,1.2*10^3】

3.符号常量

定义出来的常量(用#define)

#define 符号 常量
//#define A 100,此时A为符号常量,值为100
//不能再给A赋值(常量不能改)

注:1.符号常量不能再次赋值
2.符号常量不分全局还是局部,定义后整个程序以下都可使用

4.const 修饰的常量

在创建变量前在变量类型前加const(后续不能再此修饰该变量)

const date_type name = 常量
//const int a = 100

本质上是变量,但是const修饰后不能再改了

赞(0)
未经允许不得转载:网硕互联帮助中心 » 补:变量与常量
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!