> For the complete documentation index, see [llms.txt](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/7.-expressoes-de-atribuicao/atribuicao-modificadora.md).

# Atribuição Modificadora

Você pode abreviar a construção comum

```c
lvalue = lvalue + expressão
```

como

```c
lvalue += expressão
```

Isso é conhecido como uma *atribuição modificadora*. Por exemplo,

```c
i = i + 5;
i += 5;
```

mostra duas instruções equivalentes. A primeira usa atribuição simples; a segunda usa atribuição modificadora.

A atribuição modificadora funciona com qualquer operador aritmético binário. Por exemplo, você pode subtrair algo de um *lvalue* assim:

```c
lvalue -= expression
```

ou multiplicá-lo por uma certa quantia assim:

```c
lvalue *= expression
```

ou deslocá-lo por uma certa quantia assim:

```c
lvalue <<= expression
lvalue >>= expression
```

Na maioria dos casos, esse recurso não adiciona mais poder à linguagem, mas fornece uma conveniência substancial. Além disso, quando o *lvalue* contém código que possui efeitos colaterais, a atribuição simples executa esses efeitos colaterais duas vezes, enquanto a atribuição modificadora os executa apenas uma vez. Por exemplo,

```c
x[foo ()] = x[foo ()] + 5;
```

chama `foo` duas vezes, e ele pode retornar valores diferentes a cada vez. Se `foo ()` retornar 1 na primeira vez e 3 na segunda vez, o efeito pode ser somar `x[3]` e 5 e armazenar o resultado em `x[1]`, ou somar `x[1]` e 5 e armazenar o resultado em `x[3]`. Não sabemos qual dos dois ocorrerá, porque C não especifica qual chamada a `foo` é computada primeiro.

Tal instrução não é bem definida e não deve ser usada.

Por outro lado,

```c
x[foo ()] += 5;
```

é bem definida: chama `foo` apenas uma vez para determinar qual elemento de `x` ajustar, e ajusta esse elemento somando 5 a ele.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/7.-expressoes-de-atribuicao/atribuicao-modificadora.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
