answersLogoWhite

0


Best Answer

Every element of a pointer array is a pointer, therefore to access the memory being pointed at by an element, dereference the element. For example:

#include<iostream>

int main (void) {

int* a[10] = {nullptr};

for (int i=0; i<10; ++i) {

a[i] = new int (i+1);

}

std::cout << "Address of array:\n";

std::cout << "a = 0x" << &a << std::endl;

std::cout << "Address of each element in the array:\n";

for (int i=0; i<10; ++i) {

std::cout << "a[" << i << "] = 0x" << &a[i] << std::endl;

}

std::cout << "Value of each element in the array:\n";

for (int i=0; i<10; ++i) {

std::cout << "a[" << i << "] = 0x" << a[i] << std::endl;

}

std::cout << "Dereferenced value of each element in the array:\n";

for (int i=0; i<10; ++i) {

std::cout << "a[" << i << "] = " << *a[i] << std::endl;

}

for (int i=0; i<10; ++i) {

delete a[i];

}

}

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you display the contents of the memory addresses stored in an element of pointer array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What pointer points to the next free element?

Presumably you are referring to the next unused element of an array. If your array contains unused elements then it is up to you, the programmer, to keep track of them. Typically you will do this by placing all unused elements at the end of the array. Knowing the array's overall capacity (in elements) and the number of elements that are currently in use, it is trivial to compute the address of the next free element; there is no need to maintain a separate pointer. Perhaps you are referring to the (call) stack pointer. Call stacks are defined by the system. In 8086 architecture, the call stack is a fixed-length region of contiguous memory addresses allocated to a thread (every thread has its own call stack). The call stack extends downwards into lower memory addresses. The stack pointer (SP) register refers to the last element pushed onto the stack (the lowest used address). Note that it cannot possibly refer to the next unused element given that the length of an unused element cannot be determined until an element is actually pushed onto the stack. That is, if the element being pushed were 2 addresses (or bytes) in length, the SP will be decremented by 2 addresses and the new element will be placed at the new address. When we subsequently pop that element, the SP is simply incremented by 2 addresses.


C program pointers to pointers examples?

Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;


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 top pointer of stack?

top pointer of a stack is the pointer that refers to the top most element of the stack.


What is list?

Each element has a pointer to the next element, except for the last one.


What is singling?

Each element has a pointer to the next element, except for the last one.


What does a series of number signs mean in a cell?

Assuming you mean a cell in a spreadsheet program, when the contents are displayed as #####, it usually means the cell is not wide enough to display the contents. One way to widen the cell is to click and drag the mouse pointer at the edge of the column header. Another is to select the column and change the column width.


What is single list?

Each element has a pointer to the next element, except for the last one.


What is the time taken to insert an element after an element pointed by some pointer?

Constant time.


What is pointer to pointer with examle?

int main (int argc, char **argv):Hereargv is a pointer to a pointer (points to the first element of a pointer-array)argv[0] is a pointer (points to the first character of a string)argv[0][0] is a character


What is link list and type of link list?

A linked list is a set of elements, usually structures, where each element contains a pointer or index to the "next" element, along with the data represented by the element.Often, the elements are allocated from the heap. Sometimes, a fixed number of elements is contained in an array. In the first case, pointers are used. In the second case, indices are used.Types of linked lists are ... In an array implementation, read pointer as index.Singly linked - there is a head pointer, and one next pointer per element. The last element's pointer is null. This type of list can be traversed in only one direction.Doubly linked - there is a head pointer, and each element contains two pointers, one to the previous element and one to the next element. This type of list can be traversed in two directions, making insertion and deletion a bit easier, at the cost of extra memory.Circularly linked - the same as Singly or Doubly linked, except that the last element's pointer points back to the first element's pointer. These types of lists are often used as queues.


When can ScreenTips be useful?

ScreenTips are small windows that display descriptive text when you rest the pointer over a shape. Use ScreenTips to display extra information for a shape.