The std::to_address, introduced in C++20, is used to obtain the address represented by the specified pointer without forming a reference to the pointee. The existing std::addressof cannot do std::addressof(*ptr) because *ptr isn’t always an object. The std::to_address solves these issues for us.
template class Ptr constexpr auto to_address(const Ptr& p) noexcept; template class T constexpr T* to_address(T* p) noexcept;
Parameters: This method accepts a parameter p which is the fancy or raw pointer whose address is to be found.
Return value: This method returns the Raw pointer that represents the address of pointer p.
Below examples demonstrate the use of std::address
Pointer to Memory allocated: 0x1512c20 Pointer to Memory deleted: 0x1512c20
Using unique pointers Address of pointer to 15: 0x181ec30 Address of pointer to 17: 0x181ec50 Using dumb pointers Address of pointer to 17: 0x7fff6b454398 Address of pointer to 18: 0x7fff6b45439c
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- std::less in C++ with Examples
- cin get() in C++ with Examples
- Pi(π) in C++ with Examples
- ratio_equal() in C++ with examples
- ios bad() function in C++ with Examples
- C/C++ if else if ladder with Examples
- C/C++ do while loop with Examples
- C/C++ if statement with Examples
- C/C++ if else statement with Examples
- ios eof() function in C++ with Examples
- C/C++ while loop with Examples
- std::is_heap( ) in C++ with Examples
- ratio_not_equal() in C++ with examples
- std::equal_to in C++ with Examples
- C/C++ For loop with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.