answersLogoWhite

0


Best Answer

A pointer is a variable that can be used to store any memory address, including the null address (represented by the nullptr value). To access any non-null memory address via a pointer, simply dereference the pointer.

template<typename T>

void f (T* p) {

if (p==nullptr) return; // sanity-check

std::cout<<"1. The address of p: 0x" << std::hex << &p << std::endl; std::cout<<"2. The address pointed to by p: 0x" << std::hex << p << std::endl;

std::cout<<"3. The value pointed to by p is: " << *p << std::endl;

}

In the above example, output 3 shows how to dereference a pointer.

Note that this example will only compile if std::ostream::operator<< is overloaded to handle a type T. All primitive data types such as int and float are supported by default but all user-defined types require an explicit overload.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

You access memory with a pointer or a reference to the memory. To allocate memory dynamically, use calloc or malloc (C or C++) or new (C++ only).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you access memory dynamically in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a C plus plus statement to allocate memory cells dynamically and store the memory address in a pointer to an integer named gred?

int * gred ; gred = new int [100] ; // this example snippet creates 100 ints


Instantiation of objects in c plus plus?

Objects are instantiated when statically declared or dynamically created with the new keyword.


What is called pointers-c plus plus?

Yes, C++ has pointers, which are references to memory locations. which are variables that store memory addresses, or NULL (zero). If the pointer is non-NULL, the pointer is said to dereference the object (or variable) residing at the stored memory address, which permits indirect access to that object so long as the object remains in scope.


What is the memory management operator in c plus plus?

There is no memory management operator in C++ -- it is an unmanaged language. You use the C++ new operator to allocate memory, and use the C++ delete operator to release previously allocated memory.


Casting in c plus plus?

Yes, you can cast in C++, both statically and dynamically. Objects can also be cast provided the class designer implemented the appropriate conversion operators.


Which operator is used for deallocating memory in c plus plus?

delete


What are new and delete operators in c plus plus?

New and Delete are the memory management operators in c++,like c language we use malloc() and calloc() functions to allocate memory and free() functiong to release the memory similarily we use new to allocate memory in C++ and Delete to release the allocated memory....


What is an address in C plus plus programming?

An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.


What is the default access specifier in C plus plus?

private


How does c give access to low level memory?

Define 'low level memory' first.


How do you calculate the size of a class in memory in C plus plus?

Use sizeof( ).


How does C programming give access to low level memory?

Define 'low level memory' first.