Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Assigning Addresses to Pointers | Pointers Fundamentals
C++ Pointers and References

Deslize para mostrar o menu

book
Assigning Addresses to Pointers

When working with pointers, proper initialization is important to ensure they point to valid memory locations and prevent unexpected behavior.

Address-of and Dereference operators

To assign a value to the pointer we have to use address-of operator and to access the value of the memory address we have to use dereference operator.

  • & : the address-of operator, returns the memory address of its operand;

  • * : the derefence operator , returns the value that stored in the memory address.

cpp

main

copy
12345678
#include <iostream> int main() { int variable = 10; std::cout << &variable << std::endl; std::cout << *(&variable) << std::endl; }

Using the address-of operator, we can assign these addresses to pointers, creating a direct link between the pointer and the memory location it points to.

Tarefa

Swipe to start coding

  1. Declare a pointer with an appropriate data type.
  2. Initialize it with a variable memory address.
  3. Output both the memory address the pointer points to and the value it holds.

Solução

cpp

solution

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 2

Pergunte à IA

expand
ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

book
Assigning Addresses to Pointers

When working with pointers, proper initialization is important to ensure they point to valid memory locations and prevent unexpected behavior.

Address-of and Dereference operators

To assign a value to the pointer we have to use address-of operator and to access the value of the memory address we have to use dereference operator.

  • & : the address-of operator, returns the memory address of its operand;

  • * : the derefence operator , returns the value that stored in the memory address.

cpp

main

copy
12345678
#include <iostream> int main() { int variable = 10; std::cout << &variable << std::endl; std::cout << *(&variable) << std::endl; }

Using the address-of operator, we can assign these addresses to pointers, creating a direct link between the pointer and the memory location it points to.

Tarefa

Swipe to start coding

  1. Declare a pointer with an appropriate data type.
  2. Initialize it with a variable memory address.
  3. Output both the memory address the pointer points to and the value it holds.

Solução

cpp

solution

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 2
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt