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

Course Content

C++ Pointers and References

C++ Pointers and References

1. Pointers Fundamentals
2. Pointer Arithmetic
3. References Fundamentals
4. Dynamic Memory Allocation

bookAssigning Addresses to Pointers

When working with pointers, proper initialization is essential 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.

Task
test

Swipe to show code editor

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2
toggle bottom row

bookAssigning Addresses to Pointers

When working with pointers, proper initialization is essential 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.

Task
test

Swipe to show code editor

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2
toggle bottom row

bookAssigning Addresses to Pointers

When working with pointers, proper initialization is essential 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.

Task
test

Swipe to show code editor

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

When working with pointers, proper initialization is essential 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.

Task
test

Swipe to show code editor

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 2
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt