> 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/14.-ponteiros/desreferenciando-ponteiros.md).

# Desreferenciando Ponteiros

O principal uso de um valor de ponteiro é desreferenciá-lo (acessar os dados para os quais ele aponta) com o operador unário ‘`*`’. Por exemplo, `*&i` é o valor no endereço de `i` — que é justamente `i`. As duas expressões são equivalentes, desde que `&i` seja válido.

Uma expressão de desreferência de ponteiro cujo tipo é um dado (e não uma função) é um *lvalue*.

Os ponteiros se tornam realmente úteis quando os armazenamos em algum lugar e os usamos depois. Aqui está um exemplo simples para ilustrar essa prática:

```c
{
  int i;
  int *ptr;

  ptr = &i;

  i = 5;

  …

  return *ptr;   /* Retorna 5, obtido de i. */
}
```

Isso mostra como declarar a variável `ptr` com o tipo `int *` (ponteiro para `int`), armazenar nela um valor de ponteiro (apontando para `i`) e usá-lo depois para obter o valor do objeto para o qual ele aponta (o valor em `i`).

Aqui está outro exemplo de uso de um ponteiro para uma variável:

```c
/* Define a variável global i. */
int i = 2;

int
foo (void)
{
  /* Armazena o endereço da variável global i. */
  int *global_i = &i;

  /* Declara uma i local, ocultando a i global. */
  int i = 5;

  /* Imprime o valor da i global e da i local. */
  printf ("global i: %d\nlocal i: %d\n", *global_i, i);
  return i;
}
```

É claro que, em um programa real, seria muito mais limpo usar nomes diferentes para essas duas variáveis, em vez de chamar ambas de `i`. Mas é difícil ilustrar esse ponto sintático com um código “limpo”. Se alguém puder fornecer um exemplo útil para ilustrar isso com mais clareza, ele será bem-vindo.


---

# 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/14.-ponteiros/desreferenciando-ponteiros.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.
