ArticleslgStudy

computer science

Value (computer science)

Value (computer science) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Value (computer science) rather than just read about it. In short: In computer science and software programming, a value is the representation of some entity that can be manipulated by a program. The members of a type are the values of that type.

Key takeaways

  • Value (computer science) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Value (computer science) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Value (computer science) from memory before moving on to harder problems.

Reference excerpt

In computer science and software programming, a value is the representation of some entity that can be manipulated by a program. The members of a type are the values of that type. The "value of a variable" is given by the corresponding mapping in the environment. In languages with assignable variables, it becomes necessary to distinguish between the r-value (or contents) and the l-value (or location) of a variable. In declarative (high-level) languages, values have to be referentially transparent. This means that the resulting value is independent of the location of the expression needed to compute the value. Only the contents of the location (the bits, whether they are 1 or 0) and their interpretation are significant.

Value category Despite its name, in the C++ language standards this terminology is used to categorize expressions, not values.

Assignment: l-values and r-values Some languages use the idea of l-values and r-values, deriving from the typical mode of evaluation on the left and right-hand side of an assignment statement. An l-value refers to an object that persists beyond a single expression. An r-value is a temporary value that does not persist beyond the expression that uses it. The notion of l-values and r-values was introduced by Combined Programming Language (CPL). The notions in an expression of r-value, l-value, and r-value/l-value are analogous to the parameter modes of input parameter (has a value), output parameter (can be assigned), and input/output parameter (has a value and can be assigned), though the technical details differ between contexts and languages.

R-values and addresses In many languages, notably the C family, l-values have storage addresses that are programmatically accessible to the running program (e.g., via some address-of operator like & in C/C++), meaning that they are variables or de-referenced references to a certain memory location. R-values can be l-values (see below) or non-l-values—a term only used to distinguish from l-values. Consider the C expression 4 + 9. When executed, the computer generates an integer value of 13, but because the program has not explicitly designated where in the computer this 13 is stored, the expression is a non l-value. On the other hand, if a C program declares a variable x and assigns the value of 13 to x, then the expression x has a value of 13 and is an l-value. In C, the term l-value originally meant something that could be assigned to (hence the name, indicating it is on the left side of the assignment operator), but since the reserved word const (constant) was added to the language, the term is now 'modifiable l-value'. In C++11 a special semantic-glyph && exists ( not to be confused with the && operator used for logical operations ), to denote the use/access of the expression's address for the compiler only; i.e., the address cannot be retrieved using the address-of & operator during the run-time of the program (see the use of move semantics). The addition of move semantics complicated the value classification taxonomy by adding to it the concept of an x-value (expiring value) which refers to an object near the end of its lifetime whose resources can be reused (typically by moving them). This also lead to the creation of the categories gl-value (generalized l-value) which are l-values and x-values and pr-values (pure r-values) which are r-values that are not x-values. This type of reference can be applied to all r-values including non-l-values as well as l-values. Some processors provide one or more instructions which take an immediate value, sometimes referred to as "imm" for short. An immediate value is stored as part of the instruction which employs it, usually to load into, add to, or subtract from, a register. The other parts of the instruction are the opcode, and destination. The latter may be implicit. (A non-immediate value may reside in a register, or be stored elsewhere in memory, requiring the instruction to contain a direct or indirect address [e.g., index register address] to the value.) The l-value expression designates (refers to) an object. A non-modifiable l-value is addressable, but not assignable. A modifiable l-value allows the designated object to be changed as well as examined. An r-value is any expression, a non-l-value is any expression that is not an l-value. One example is an "immediate value" (see above) and consequently not addressable.

In assembly language A value can be virtually any kind of data by a given data type, for instance a string, a digit, a single letter. Processors often support more than one size of immediate data, e.g., 8- or 16-bit, employing a unique opcode and mnemonic for each instruction variant. If a programmer supplies a data value that will not fit, the assembler issues an "Out of range" error message. Most assemblers allow an immediate value to be expressed as ASCII, decimal, hexadecimal, octal, or binary data. Thus, the ASCII character 'A' is the same as 65 or 0x41. The byte order of strings may differ between processors, depending on the assembler and computer architecture.

See also Undefined value Value (mathematics) Value-level programming

Notes

References Mitchell, John C. (1996). Foundations for Programming Languages. The MIT Press. ISBN 0-262-13321-0. Strachey, Christopher (2000). "Fundamental Concepts in Programming Languages". Higher-Order and Symbolic Computation. 13: 11–49. doi:10.1023/A:1010000313106. S2CID 14124601.

External links Value Object Transfer Object Pattern

Worked examples

Example 1 — a first encounter with Value (computer science)

Start with the simplest possible case. Write down what Value (computer science) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Value (computer science) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Value (computer science) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Value (computer science)

In research
Value (computer science) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Value (computer science) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Value (computer science) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer data, Programming language concepts, Type theory, so understanding it makes those chapters shorter.
In everyday life
Look for Value (computer science) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Value (computer science)” →

How to study Value (computer science) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Value (computer science) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Value (computer science) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Value (computer science) in simple terms?

In computer science and software programming, a value is the representation of some entity that can be manipulated by a program. The members of a type are the values of that type.

Why does Value (computer science) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Value (computer science)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Value (computer science).

Tags

  • Computer data
  • Programming language concepts
  • Type theory

Keep exploring