博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++全局变量_C全局变量
阅读量:2511 次
发布时间:2019-05-11

本文共 1214 字,大约阅读时间需要 4 分钟。

c++全局变量

In the post I introduced how to work with variables.

在文章中,我介绍了如何使用变量。

In this post I want to mention the difference between global and local variables.

在这篇文章中,我想提到全局变量和局部变量之间的区别。

A local variable is defined inside a function, and it’s only available inside that function.

局部变量是在函数内部定义的,并且仅在该函数内部可用。

Like this:

像这样:

#include 
int main(void) { char j = 0; j += 10; printf("%u", j); //10}

j is not available anywhere outside the main function.

jmain功能之外的任何地方都不可用。

A global variable is defined outside of any function, like this:

全局变量是在任何函数之外定义的,如下所示:

#include 
char i = 0;int main(void) { i += 10; printf("%u", i); //10}

A global variable can be accessed by any function in the program. Access is not limited to reading the value: the variable can be updated by any function.

程序中的任何函数都可以访问全局变量。 访问不仅限于读取值:可以通过任何函数更新变量。

Due to this, global variables are one way we have of sharing the same data between functions.

因此,全局变量是我们在函数之间共享相同数据的一种方式。

The main difference with local variables is that the memory allocated for variables is freed once the function ends.

与局部变量的主要区别在于,函数结束后,将释放为变量分配的内存。

Global variables are only freed when the program ends.

仅在程序结束时才释放全局变量。

翻译自:

c++全局变量

转载地址:http://bhmgb.baihongyu.com/

你可能感兴趣的文章
spfile
查看>>
Team Foundation Service更新:改善了导航和项目状态速查功能
查看>>
0x13 链表与邻接表
查看>>
js封装设置获取cookie
查看>>
二值图像连通区域标记
查看>>
MVC in Javascript
查看>>
eclipse 创建的Android工程的结构
查看>>
第8章 Android异常与性能优化相关面试问题
查看>>
linux 定时备份文件夹
查看>>
有道单词导入 大量有道单词 生词本 批量导入 添加 有道单词XML 背单词
查看>>
jQuery Easing动画效果扩展插件
查看>>
bzoj 1002 [FJOI2007]轮状病毒 Matrix-Tree定理+递推
查看>>
Selenium WebDriver- 操作JavaScript的Alert弹窗
查看>>
娘的,自己的求逆序对模板又不好使了。。。。。。。。
查看>>
C#面向对象模式设计第十四讲:Template Method 模板模式(行为型模式)
查看>>
linux后台运行命令:&和nohup
查看>>
springboot + shiro学习(配置SecurityManager,Realm)
查看>>
http://desk.zol.com.cn/1600x900/
查看>>
Linux基础之命令练习Day3-文件管理:cat,tar,gzip,vim,ln
查看>>
iOS中使用nil NULL NSNULL的区别
查看>>