-
Variables are one of the more fundamental concepts in computer science. Programmers speak of declaring and initializing variables and assigning values to them. Put simply, variables are references to information stored in memory.
Variable vs. Constant
The word variable means "able to be changed," and so variables are references to information in memory that a program can change over time. This is different than constants, which are required to remain the same.
Common Types
Though variables are stored in memory as a binary numerical value, most languages interpret the variables into a type. Common types include integers (for whole numbers), floats (for numbers with a decimal) and characters.
Static vs. Dynamic Typing
Languages use either static or dynamic typing. Static typing requires that a declared variable can have only one type within a scope, whereas dynamic typing stores the type with the variable in memory, allowing a given variable to change types as a program goes on.
Pass-by Value
A language uses pass-by value if, when it passes a variable into a function, the value contained by the variable is copied into a new memory location for use in the function.
Pass-by Reference
A language uses pass-by reference if, when it passes a variable into a function, the address of the location in memory is used by the function.
Source:
Copyright 2023, Wired Ivy, LLC