什么是变量?

164 阅读1分钟

背景:

再次学习一门新的语言时,我发现以往会很容易忽略一些常见的编程名词的含义,所以想在这次学习rust的过程中,顺便弄清楚它们在编程中的含义。这次我想搞清楚的就是“变量”,为什么会有变量,它在 programming 中起着什么样的作用?

定义:

我找到一段英文的描述,引自Variable(毕竟早期的编程大都源自美国,国内翻译过来可能会有所偏差),期望可以得到比较准确的描述。

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

解释下就有以下几点:

  1. 变量用于存储在计算机编程中引用和操作的信息;
  2. 它提供了一种用描述性名称标记数据的方法,因此程序才可以被其他编程人员和定义变量的人清晰的理解;

总结:

在编程中,程序员可以将变量视为保存信息的容器。变量的目的是在内存中标记和存储数据,然后在整个程序中使用此数据(通过定义的变量名)

思考——在计算机中引用是什么?Reference (computer science)