> 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/8.-expressoes-de-controle-de-execucao/operadores-logicos-e-atribuicoes.md).

# Operadores Lógicos e Atribuições

Existem casos em que atribuições aninhadas dentro de uma condição podem realmente tornar um programa mais fácil de ler. Aqui está um exemplo usando um tipo hipotético `list` que representa uma lista; ele testa se a lista tem pelo menos dois elementos, utilizando funções hipotéticas, `nonempty`, que retorna verdadeiro se o argumento for uma lista não vazia, e `list_next`, que avança de um elemento da lista para o próximo. Assumimos que uma lista nunca é um ponteiro nulo, de modo que as expressões de atribuição são sempre “verdadeiras.”

```c
if (nonempty (list)
    && (temp1 = list_next (list))
    && nonempty (temp1)
    && (temp2 = list_next (temp1)))
  …  /* usa temp1 e temp2 */
```

Aqui aproveitamos o operador ‘&&’ para evitar a execução do restante do código se uma chamada a `nonempty` retornar “falso.” O único lugar natural para colocar as atribuições é entre essas chamadas.

Seria possível reescrever isso como várias instruções, mas isso poderia tornar o código muito mais pesado. Por outro lado, quando o teste é ainda mais complexo do que este, dividi-lo em várias instruções pode ser necessário para manter a clareza.

Se uma lista vazia for um ponteiro nulo, podemos dispensar a chamada a `nonempty`:

```c
if ((temp1 = list_next (list))
    && (temp2 = list_next (temp1)))
  …
```


---

# 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/8.-expressoes-de-controle-de-execucao/operadores-logicos-e-atribuicoes.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.
