A variable (pronounced /ˈveərɪəbl/) is an attribute of a physical or an abstract system which may change its value while it is under observation. System (from Latin systēma, in turn from Greek systēma is a set of interacting or interdependent Entities, real or abstract Observation is either an activity of a living being (such as a Human) which senses and assimilates the Knowledge of a Phenomenon, or the recording of data Examples include the height of a child, the temperature across a state, or the input to a function. The Mathematical concept of a function expresses dependence between two quantities one of which is given (the independent variable, argument of the function
The concept variable is used in all areas of mathematics, science and engineering. The term "concept" is traced back to 1554–60 ( l conceptum - something conceived but what is today termed "the classical theory of concepts" is the theory of Aristotle Mathematics is the body of Knowledge and Academic discipline that studies such concepts as Quantity, Structure, Space and Science (from the Latin scientia, meaning " Knowledge " or "knowing" is the effort to discover, and increase human understanding Engineering is the Discipline and Profession of applying technical and scientific Knowledge and
In mathematics and computer science, a variable is usually represented by one or more words or symbols, such as "time" or "'x'". Mathematics is the body of Knowledge and Academic discipline that studies such concepts as Quantity, Structure, Space and Computer science (or computing science) is the study and the Science of the theoretical foundations of Information and Computation and their In mathematics, beginners are often confused by the fact that the letter 'x' is sometimes used for a variable, as in the expression y = x2, and sometimes for an "unknown", as in the expression 2x = 6.
In the physical sciences and engineering this term has a similar meaning: a variable is a quantity whose value may vary over the course of an experiment (including simulations), across samples, or during the operation of a system. Physical science is an encompassing term for the branches of Natural science and Science that study non-living systems in contrast to the biological sciences Engineering is the Discipline and Profession of applying technical and scientific Knowledge and
In modeling, variables are distinct from parameters, although what is a variable in one context may be a parameter in another. In Mathematics, Statistics, and the mathematical Sciences a parameter ( G auxiliary measure) is a quantity that defines certain characteristics For more on this distinction, see the article on "parameter". In Mathematics, Statistics, and the mathematical Sciences a parameter ( G auxiliary measure) is a quantity that defines certain characteristics
In applied statistics, a variable is a measurable factor, characteristic, or attribute of an individual or a system—in other words, something that might be expected to vary over time or between individuals. Statistics is a mathematical science pertaining to the collection analysis interpretation or explanation and presentation of Data. Random variables are an idealization of this in mathematical statistics, where they are defined as measurable functions from a probability space to a measurable space. A random variable is a rigorously defined mathematical entity used mainly to describe Chance and Probability in a mathematical way Mathematical statistics is the study of Statistics from a purely mathematical standpoint using Probability theory as well as other branches of Mathematics In Mathematics, measurable functions are Well-behaved functions between measurable spaces. A probability space, in Probability theory, is the conventional Mathematical model of Randomness.
Contents |
The symbol x commonly denotes an unknown variable. The musical instrument is spelled Cymbal. A symbol is something --- such as an object, Picture, written word a sound a piece In Semiotics, denotation is the surface or literal meaning encoded to a signifier and the Definition most likely to appear in a Dictionary Even though any letter can be used, x is the most common choice. This usage can be traced back to the Arabic word šay' شيء = “thing”, which in translated algebra texts and similar was taken into Old Spanish with the pronunciation “šei”, which was written xei, which was soon habitually abbreviated to x. Algebra is a branch of Mathematics concerning the study of structure, relation, and Quantity. (The Spanish pronunciation of “x” has changed since. ) But some sources say that this x is an abbreviation of Latin causa which was a translation of Arabic شيء. That started the habit of using letters to represent quantities in algebra. Algebra is a branch of Mathematics concerning the study of structure, relation, and Quantity. In mathematics, an “italicized x” (
) is often used to avoid potential confusion with the multiplication symbol. In Typography, italic type /ɪˈtælɪk/ or /aɪˈtælɪk/ refers to cursive Typefaces based on a stylized form of calligraphic Handwriting. By extension beyond mathematics, “X” has come to represent a generic placeholder variable whose value is unknown or secret, as in project X or mister X.
Variables are used in open sentences. A OPEN sentence (usually an equation or inequality is described as "open" in the sense that its truth value is meaningless until its variables are replaced with specific numbers at which For instance, in the formula x + 1 = 5, x is a variable which represents an "unknown" number. X is the twenty-fourth letter in the modern Latin alphabet. Its name in English is spelled ex or occasionally ecks (ɛks plural exes A number is an Abstract object, tokens of which are Symbols used in Counting and measuring. Variables are often represented by letters of the Roman alphabet, but are also represented by letters of other alphabets, such as the Greek alphabet, as well as various other symbols. A letter is an element in an Alphabetic system of writing such as the Greek alphabet and its descendants An alphabet is a standardized set of letters basic written symbols each of which roughly represents a Phoneme, a Spoken language, either The Greek alphabet (Ελληνικό αλφάβητο is a set of twenty-four letters that has been used to write the Greek language since the late 9th or early The musical instrument is spelled Cymbal. A symbol is something --- such as an object, Picture, written word a sound a piece In this sense, variables are used as a "fill-in-the-blank" within many fields (mathematics, linguistics, etc. )
The names of variables used within a discipline often follow some naming convention. A naming convention is a convention for naming things The intent is to allow useful information to be deduced from the names based on regularities
In mathematics, very common letters for variables are "x", "y", "n", "a" and "b". "x" and "y" are often used because they correspond to the two axes on a graph, while "a" and "b" are used as the coefficients of x and y in the general form of a linear equation. "n" is often used in statistical analysis, eg, "n" being the number of subjects in a study.
Variables are useful in mathematics because they allow instructions to be specified in a general way. If one were forced to use actual values, then the instructions would only apply in a more narrow set of situations. For example:
In the above example, the variable x is a "placeholder" for any number. One important thing we are assuming is that the value of each occurrence of x is the same—that x does not get a new value between the first x and the second x.
(Note that in computer programming languages without referential transparency, changes such as this can occur. A programming language is an Artificial language that can be used to write programs which control the behavior of a machine particularly a Computer. Variables in computer programming are also useful for this reason. The term "variable", as used by programmers, is different from the meaning of "variable" as used by mathematicians. )
In statistics, variables refer to measurable attributes, as these typically vary over time or between individuals. Statistics is a mathematical science pertaining to the collection analysis interpretation or explanation and presentation of Data. Variables can be discrete (taking values from a finite or countable set), continuous (having a continuous distribution function), or neither. In Probability theory, a Probability distribution is called discrete if it is characterized by a Probability mass function. In Probability theory, a Probability distribution is called continuous if its Cumulative distribution function is continuous. In Mathematics, a continuous function is a function for which intuitively small changes in the input result in small changes in the output In Probability theory and Statistics, the cumulative distribution function (CDF, also probability distribution function or just distribution function Temperature is a continuous variable, while the number of legs of an animal is a discrete variable. This concept of a variable is widely used in the natural, medical and social sciences. In Science, the term natural science refers to a naturalistic approach to the study of the Universe, which is understood as obeying rules or law of Biomedical research (or experimental medicine) in general simply known as medical research, is the Basic research or Applied research conducted The social sciences comprise academic disciplines concerned with the study of the social life of human groups and individuals including Anthropology, Communication studies
In causal models, a distinction is made between "independent variables" and "dependent variables", the latter being expected to vary in value in response to changes in the former. Causality (but not causation) denotes a necessary relationship between one event (called cause and another event (called effect) which is the direct consequence Dependent variables and independent variables refer to values that change in relationship to each other Dependent variables and independent variables refer to values that change in relationship to each other In other words, an independent variable is presumed to potentially affect a dependent one. In experiments, independent variables include factors that can be altered or chosen by the researcher independent of other factors.
For example, in an experiment to test whether or not the boiling point of water changes with altitude, the altitude is under direct control and is the independent variable, and the boiling point is presumed to depend upon it and is therefore the dependent variable. The collection of results from an experiment, or information to be used to draw conclusions, is known as data. Debt AIDS Trade in Africa (or DATA) is a Multinational non-government organization founded in January 2002 in London by U2 's It is often important to consider which variables to allow for, or to directly control or eliminate, in the design of experiments. Design of experiments, or experimental design, is the design of all information-gathering exercises where variation is present whether under the full control of the experimenter
There are also quasi-independent variables, which are those variables that are used by researcher as a grouping mechanism, without manipulating the variable. An example of this would be separating people into groups by their gender. Gender cannot be manipulated, but it is used as a way to group. Another example would be separating people on the amount of coffee they drank before beginning an experiment. The researcher cannot change the past, but can use it to differentiate the groups.
While independent variables can refer to quantities and qualities that are under experimental control, they can also include extraneous factors that influence results in a confusing or undesired manner.
In general, if strongly confounding variables exist that can substantially affect the result, then this makes it more difficult to interpret the results. In statistics a confounding variable (also confounding factor, lurking variable, a confound, or confounder) is an Extraneous variable For example, a study into the incidence of cancer with age will also have to take into account variables such as income (poorer people may have less healthy lives), location (some cancers vary depending on diet and sunlight), stress and lifestyle issues (cancer may be related to these more than age), and so on. In Geography, location is a position or point in Physical space that something occupies on Earths' surface The term lifestyle was originally coined by Austrian psychologist Alfred Adler in 1929 Failure to at least consider these factors can lead to grossly inaccurate deductions. For this reason, controlling unwanted variables is important in research.
Variables in computer programming are very different from variables in mathematics and the apparent similarity is source of much confusion. Extraneous variables are Variables other than the independent variable that may bear any effect on the behaviour of the subject being studied An intervening Variable is a hypothetical internal state that is used to explain relationships between observed variables such as independent and dependent variables in The level of Measurement of a Variable in Mathematics and Statistics is a classification that is used to describe the nature of information Variables in most of mathematics (those that are extensional and referentially transparent) are time-independent unknowns, while in programming a variable can associate with different values at different times (as they are intensional). Not to be confused with the homophone Intention; or the related concept of Intentionality.
In computer programming a variable is a special value (also often called a reference) that has the property of being able to be associated with another value (or not). What is variable across time is the association. Obtaining the value associated with a variable is often called dereferencing, and creating or changing the association is called assignment.
Variables are usually named by an identifier, but they can be anonymous, and variables can be associated with other variables.
In the computing context, variable identifiers often consist of alphanumeric strings. In Computer programming and some branches of Mathematics, a string is an ordered Sequence of Symbols. These identifiers are then used to refer to values in computer memory. In Computer science, a value is a sequence of Bits that is interpreted according to some Data type. This convention of matching identifiers to values is but one of several alternative programmatic conventions for accessing values in computer memory (see also: reflection (computer science)). In Computer science, reflection is the process by which a Computer program can observe and modify its own structure and behavior
In some programming languages, specific characters (known as sigils) are prefixed or appended to variable identifiers to indicate the variable's type. In Computer programming a Naming convention is a set of rules for choosing the character sequence to be used for Identifiers in Source code and documentation In Computer science, Identifiers ( IDs) are lexical tokens that name entities. A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers (i In Computer programming, a sigil (pronounced /'sɪdʒɪl/ or /'sɪg For example:
In computer source code, a variable name is one way to bind a variable to a memory location; the corresponding value is stored as a data object in that location so that the object can be accessed and manipulated later via the variable's name. In Computer science, source code (commonly just source or code) is any sequence of statements or declarations written in some Human-readable In Programming languages name binding is the association of values with Identifiers An identifier bound to a value is said to reference In its simplest embodiment an object is an allocated region of storage
In a spreadsheet, a cell may contain a formula with references to other cells. A spreadsheet is a Computer application that simulates a paper worksheet In Mathematics and in the Sciences a formula (plural formulae, formulæ or formulas) is a concise way of expressing information A spreadsheet is a Computer application that simulates a paper worksheet Such a cell reference is a kind of variable; its value is the value of the referenced cell (see also: reference (computer science)). In Computer science, a reference is an object containing information which refers to data stored elsewhere as opposed to containing the data itself
The scope of a variable describes where in a program's text, the variable may be used, while the extent (or lifetime) describes when in a program's execution a variable has a value. In Computer programming, scope is an enclosing context where values and expressions are associated The scope of a variable is actually a property of the name of the variable, and the extent is a property of the variable itself.
A variable name's scope affects its extent.
Scope is a lexical aspect of a variable. In Computer programming, scope is an enclosing context where values and expressions are associated Most languages define a specific scope for each variable (as well as any other named entity), which may differ within a given program. The scope of a variable is the portion of the program code for which the variable's name has meaning and for which the variable is said to be "visible". Entrance into that scope typically begins a variable's lifetime and exit from that scope typically ends its lifetime. For instance, a variable with "lexical scope" is meaningful only within a certain block of statements or subroutine. In Computer science, a subroutine ( function, method, procedure, or subprogram) is a portion of code within a larger A "global variable", or one with indefinite scope, may be referred to anywhere in the program. In Computer programming, a global variable is a variable that is accessible in every scope. It is erroneous to refer to a variable where it is out of scope. Lexical analysis of a program can determine whether variables are used out of scope. In Computer science, lexical analysis is the process of converting a sequence of characters into a sequence of tokens In compiled languages, such analysis can be performed statically at compile time. In Computer science, compile time refers to either the operations performed by a Compiler (the "compile-time operations" or Programming language
Extent, on the other hand, is a runtime (dynamic) aspect of a variable. In Computer programming, scope is an enclosing context where values and expressions are associated Each binding of a variable to a value can have its own extent at runtime. In Computer science, binding is the creation of a simple Reference to something that is larger and more complicated and used frequently The extent of the binding is the portion of the program's execution time during which the variable continues to refer to the same value or memory location. A running program may enter and leave a given extent many times, as in the case of a closure. In Computer science, a closure is a function that is evaluated in an environment containing one or more Bound variables When called the function can access
In portions of code, a variable in scope may never have been given a value, or its value may have been destroyed. Such variables are described as "out of extent" or "unbound". In many languages, it is an error to try to use the value of a variable when it is out of extent. In other languages, doing so may yield unpredictable results. In Computer science, undefined behavior is a feature of some programming languages &mdash most famously C. Such a variable may, however, be assigned a new value, which gives it a new extent. By contrast, it is permissible for a variable binding to extend beyond its scope, as occurs in Lisp closures and C static variables. Global variable|Static memory allocationIn Computer programming, static variables data value persists for the life of the running process and typically have a broader scope When execution passes back into the variable's scope, the variable may once again be used.
For space efficiency, a memory space needed for a variable may be allocated only when the variable is first used and freed when it is no longer needed. A variable is only needed when it is in scope, but beginning each variable's lifetime when it enters scope may give space to unused variables. To avoid wasting such space, compilers often warn programmers if a variable is declared but not used.
It is considered good programming practice to make the scope of variables as narrow as feasible so that different parts of a program do not accidentally interact with each other by modifying each other's variables. Doing so also prevents action at a distance. Action at a distance is an Anti-pattern (a recognized common error in which behavior in one part of a program varies wildly based on difficult or impossible Common techniques for doing so are to have different sections of a program use different namespaces, or to make individual variables "private" through either dynamic variable scoping or lexical variable scoping. A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers (i In Computer programming, scope is an enclosing context where values and expressions are associated In Computer programming, scope is an enclosing context where values and expressions are associated
Many programming languages employ a reserved value (often named null or nil) to indicate an invalid or uninitialized variable. Null has several meanings in Computer programming.;Null pointer or null reference Null is a special Pointer value (or other kind of object reference
In statically-typed languages such as Java or ML, a variable also has a type, meaning that only values of a given class (or set of classes) can be stored in it. In Computer science, a type system defines how a Programming language classifies values and expressions into '''types''', how it can ML is a general-purpose Functional programming language developed by Robin Milner and others in the late 1970s at the University of Edinburgh, whose syntax A variable of a primitive type holds a value of that exact primitive type. A variable of a class type can hold a null reference or a reference to an object whose type is that class type or any subclass of that class type. A variable of an interface type can hold a null reference or a reference to an instance of any class that implements the interface. A variable of an array type can hold a null reference or a reference to an array.
In dynamically-typed languages such as Python, it is values, not variables, which carry type. In Computer science, a type system defines how a Programming language classifies values and expressions into '''types''', how it can Python is a general-purpose High-level programming language. Its design philosophy emphasizes programmer productivity and code readability In Common Lisp, both situations exist simultaneously: a variable is given a type (if undeclared, it is assumed to be T, the universal supertype) which exists at compile time. Common Lisp, commonly abbreviated CL, is a dialect of the Lisp Programming language, published in ANSI standard document Information In Computer science, a subtype is a Datatype that is generally related to another datatype (the supertype) by some notion of Substitutability Values also have types, which can be checked and queried at runtime. See type system. In Computer science, a type system defines how a Programming language classifies values and expressions into '''types''', how it can
Typing of variables also allows polymorphisms to be resolved at compile time. In Computer science, polymorphism is a Programming language feature that allows values of different Data types to be handled using a However, this is different from the polymorphism used in object-oriented function calls (referred to as virtual functions in C++) which resolves the call based on the value type as opposed to the supertypes the variable is allowed to have. In Object-oriented programming, a virtual function or virtual method is one whose behavior is defined within an inheriting class by a function with the same signature C++ (" C Plus Plus " ˌsiːˌplʌsˈplʌs is a general-purpose Programming language.
Variables often store simple data-like integers and literal strings, but some programming languages allow a variable to store values of other datatypes as well. A data type in Programming languages is an attribute of a datum which tells the computer (and the programmer something about the kind of datum it is Such languages may also enable functions to be parametric polymorphic. In Computer science, polymorphism is a Programming language feature that allows values of different Data types to be handled using a These functions operate like variables to represent data of multiple types. For example, a function named length may determine the length of a list. Such a length function may be parametric polymorphic by including a type variable in its type signature, since the amount of elements in the list is independent of the elements' types. Type signature is a term that is used in computer programming
The formal parameters of functions are also referred to as variables. For instance, in this Python code segment,
def addtwo(x): return x + 2 addtwo(5) # yields 7
and its equivalent code segment in Lisp,
(defun addtwo (x) (+ x 2)) (addtwo 5) ; yields 7
the variable named x is a parameter because it is given a value when the function is called. The integer 5 is the argument which gives x its value. In most languages, function parameters have local scope. This specific variable named x can only be referred to within the addtwo function (though of course other functions can also have variables called x).
The specifics of variable allocation and the representation of their values vary widely, both among programming languages and among implementations of a given language. Many language implementations allocate space for local variables, whose extent lasts for a single function call on the call stack, and whose memory is automatically reclaimed when the function returns. In Computer science, a local variable is a Variable that is given local scope. In Computer science, a call stack is a dynamic stack data structure which stores information about the active Subroutines of a Computer program (More generally, in name binding, the name of a variable is bound to the address of some particular block (contiguous sequence) of bytes in memory, and operations on the variable manipulate that block. In Programming languages name binding is the association of values with Identifiers An identifier bound to a value is said to reference Referencing is more common for variables whose values have large or unknown sizes when the code is compiled. In Computer science, a reference is an object containing information which refers to data stored elsewhere as opposed to containing the data itself Such variables reference the location of the value instead of the storing value itself, which is allocated from a pool of memory called the heap. In Computer science, dynamic memory allocation is the allocation of memory storage for use in a Computer program during the Runtime of that program
Bound variables have values. A value, however, is an abstraction, an idea; in implementation, a value is represented by some data object, which is stored somewhere in computer memory. In its simplest embodiment an object is an allocated region of storage The program, or the runtime environment, must set aside memory for each data object and, since memory is finite, ensure that this memory is yielded for reuse when the object is no longer needed to represent some variable's value.
Objects allocated from the heap must be reclaimed specially when the objects are no longer needed. In a garbage-collected language (such as C#, Java, and Lisp), the runtime environment automatically reclaims objects when extant variables can no longer refer to them. In Computer science, garbage collection ( GC) is a form of automatic Memory management. C# (pronounced C Sharp is a Multi-paradigm A lisp ( OE wlisp, stammering is a Speech impediment, historically also known as sigmatism. In non-garbage-collected languages, such as C, the program (and thus the programmer) must explicitly allocate memory, and then later free it, to reclaim its memory. tags please moot on the talk page first! --> In Computing, C is a general-purpose cross-platform block structured In Computing, malloc is a Subroutine provided in the C and C++ programming language 's standard libraries for performing Failure to do so leads to memory leaks, in which the heap is depleted as the program runs, risking eventual failure from exhausting available memory. In Computer science, a memory leak is a particular type of unintentional memory consumption by a Computer program where the program fails to release memory
When a variable refers to a data structure created dynamically, some of its components may be only indirectly accessed through the variable. A data structure in Computer science is a way of storing Data in a computer so that it can be used efficiently In such circumstances, garbage collectors (or analogous program features in languages that lack garbage collectors) must deal with a case where only a portion of the memory reachable from the variable needs to be reclaimed.
A constant is a datum whose value cannot be changed once it is initially bound to a value. In other words, constants cannot be assigned to. In Computer science the assignment statement sets or re-sets the value stored in the storage location(s denoted by a Variable Name. In purely functional programming, all data are constant, because there is no assignment. Purely functional is a term in Computing used to describe Algorithms Data structures or Programming languages that exclude destructive modifications In many machine assembly languages or instruction set specifications, constant values are termed immediate value because they are available immediately (often embedded as part of the instruction stream) without needing to load a value from the data cache[1]. See the terminology section below for information regarding inconsistent use of the terms assembly and assembler In Computer science, an instruction is a single operation of a processor defined by an Instruction set architecture.
Although a constant value is specified only once, the constant can be referenced multiple times in a program. Using a constant instead of specifying a value multiple times in the program can not only simplify code maintenance, but it can also supply a meaningful name for it and consolidate such constant assignments to a standard code location (for example, at the beginning).
Programming languages provide one of two kinds of constant variables:
CONST a = 60. final int a = b + 20;. For variables which are references, do not confuse constant references with immutable objects. In object-oriented and functional programming an immutable object is an object whose state cannot be modified after it is created For example, when a non-constant reference references an immutable object, that reference can be changed so that it references a different object, but the object it originally pointed to cannot be changed (i. e. other references that reference it still see the same information).
Conversely, a constant reference may reference a mutable object. In this case, the reference will always reference the same object (the reference cannot be changed); however, the object that the reference references can still be changed (and other references that also reference that object will see the change), as shown in the following example:
final StringBuffer sampleDynamicConstant = new StringBuffer ("InitialValueOfDynamicConstant"); sampleDynamicConstant. append("_AppendedText"); System. out. println(sampleDynamicConstant);
The above code produces the following output:
InitialValueOfDynamicConstant_AppendedText
In languages where a variable can be an object (i. e. C++), such a variable being constant is equivalent to the immutability of that object.
Variable interpolation (also variable substitution, variable expansion) is the process of evaluating an expression or string literal containing one or more variables, yielding a result in which the variables are replaced with their corresponding values in memory. It is a specialized instance of concatenation. For concatenation of general lists see Append. In Computer programming, string concatenation is the operation of joining two character
Languages that support variable interpolation include Perl, PHP, Ruby, and most Unix shells. NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below PHP is a computer Scripting language. Originally designed for producing Dynamic web pages it has evolved to include a Command line interface capability Ruby is a dynamic, reflective, general purpose Object-oriented programming language that combines syntax inspired by Perl with Smalltalk A Unix shell, is a command line shell that provides the traditional User interface for the Unix Operating system and for Unix-like In these languages, variable interpolation only occurs when the string literal is double-quoted, but not when it is single-quoted. The variables are recognized because variables start with a sigil (typically "$") in these languages. In Computer programming, a sigil (pronounced /'sɪdʒɪl/ or /'sɪg Ruby uses the "#" symbol for interpolation, and lets you interpolate any expression, not just variables. Ruby is a dynamic, reflective, general purpose Object-oriented programming language that combines syntax inspired by Perl with Smalltalk
For example, the following Perl code:
$name = "Nancy"; print "$name said Hello World to the crowd of people. NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below ";
produces the output:
Nancy said Hello World to the crowd of people.