# 5.4 Designators

> A designator is something that names a place where a value can be stored: a variable, an array cell or an attribute of an object.

Web page: https://pseudolearn.app/en/spec/declaraciones/designadores

> **In one sentence**
>
> A designator is something that names a place where a value can be stored: a variable, an array cell or an attribute of an object.

## 5.4.1 How it works

Not everything that can be read can be written. `x + 1` has a value, but it is not a place: there is nowhere to store anything. Statements that store values —assignment, `Read` and passing by reference— require a **designator**.

**Figure 5.4-1: Places and values**

On the left, three designators: x, notas[i] and persona.nombre. On the right, three expressions that are not: 5, x + 1 and length(t).

On the left, designators: they name a place. On the right, expressions that only have a value.

| Is a designator | Is not a designator |
| --- | --- |
| `x` | `5` |
| `notas[i]` | `x + 1` |
| `persona.nombre` | `Longitud(t)` |
| `tabla[i, j]` | `(x)` |

The indices and the receiver of a designator are evaluated **only once**, before storing:

### Program: Cells as targets

```pseudolearn
Algorithm Designadores
  Dimension notas[3] As Integer;
  Define i As Integer <- 0;
  notas[0] <- 7;
  notas[i + 1] <- notas[0] + 1;
  notas[2] <- 10;
  Write notas[0], " ", notas[1], " ", notas[2];
EndAlgorithm
```

**Output**

```text
7 8 10
```

*The program finishes normally.*

In `notas[i + 1]` the index is any expression, but `notas[…]` as a whole still names a place.

> **Common mistakes**
>
> ### Program: Reading into a number
>
> ```pseudolearn
> Algorithm LeerLiteral
>   Read 5;
> EndAlgorithm
> ```
>
> **Diagnostics**
> - `invalidReadTarget` (error, 2:8): Read target is not a valid variable or array element
>
> *The program finishes with an error.*

**In short**
- A designator names a place: variable, cell or attribute.
- Assigning, `Read` and passing by reference require a designator.
- Literals, operations, calls and parentheses are not designators.

**See also**
- [5.3 Assignment](https://pseudolearn.app/en/spec/declaraciones/asignacion.md)
- [3.4 Arrays](https://pseudolearn.app/en/spec/tipos/arreglos.md)
- [7.3 Parameters by reference](https://pseudolearn.app/en/spec/subprogramas/referencia.md)
