answersLogoWhite
notificationBell

Top Answer
User Avatar
Wiki User
Answered 2012-05-11 16:56:11

Yes. More specifically, they can be used to represent a dynamic multi-dimensional array.

As most people know, for a one-dimensional dynamic array, you simply need a pointer to the first element in the array, where each element contains an object of the same type as the pointer. The pointer can be passed around functions just as if it were a static array, the only difference being the requirement to pass the upper bound of the array as well as the array itself.

For a two-dimensional array, you need a pointer-to-pointer which points to the first element of a one-dimensional pointer array, where each pointer in that array points to a one-dimensional array of objects. The pointer-to-pointer must be the same type as the pointers and the objects.

For a three-dimensional array you need a pointer-to-pointer-to-pointer. And so on. Each additional dimension simply adds a new level of indirection, and a new level of one-dimensional pointer arrays.

Of course multi-dimensional arrays are only useful if every dimension is fully utilised and doesn't require too much in the way of resizing. If that is not the case, then you may get more efficient memory consumption from a vector of vectors (of vectors), which allows dynamic resizing at every level without having to copy existing elements. The downside is you lose the random access provided by the array.

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Related Questions


Array elements can be pointers, and pointers can point to array elements, if that's what you mean.


An array of pointers is that for eg if we have array of 10 int pointers ie int *a[10] then each element that which is stored in array are pointed by pointers. here we will have ten pointers. In pointer to an array for eg int(*a)[10] here all the elements that is all the ten elements are pointed by a single pointer.


An array of pointers is a contiguous block of memory that contains pointers to other memory locations. They essentially allow non-contiguous memory locations to be treated as if they were an actual array.


using multidimensional array


char* my_array[3]; /* an array of three pointers to char */


I guess it is an 'array of pointers'. Example:int main (int argc, char *argv[])


There is no such thing as an "array to pointer." What you might be asking is "array of pointers." An array of pointers is just that, an array in which the variables are pointers. In C this would be an array of pointer variables that are each 4 bytes in size. It is declared like this: int *pointers[3]; A pointer to an array is a pointer that points to the whole array. For example, in C if you have int numbers[5][10]; int (*pointerToArray)[10] = numbers + 2; pointerToArray points to the third element of numbers, which is itself an array.


An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.An array is when you store several data items with a single name. You only use a number to distinguish the individual items. Or two or more numbers, if you use a multidimensional array.


There is a difference: a pointer is a number that literally points to a place in memory. Arrays are groupings of a type. There is a close relationship between pointers and arrays, however: every expression with arrays (example: array[i]) can be expressed with pointers (example: *(array + i)), because for the computer, an array is just a list of pointers to the type of the array.


Followings are different type of arrany in C#, 1) Single-Dimensional Array 2) Multidimensional Array 3) Jagged Array (Array-of-Arrays)


A multidimensional array in C or C++ is simply an array of arrays, or an array of an array of arrays, etc. for however many dimensions you want. int a; // not an array int a[10]; // ten int a's int a[10][20]; // twenty int a[10]'s, or 200 int a's int a[10][20][30]; // and so on and so forth...


Use the array to maintain pointers to each stack.


You would use an array of pointers to pointers whenever you wished to implement a dynamic multi-dimensional array of 3 or more dimensions. Every multi-dimensional array can ultimately be reduced to a one-dimensional array where each element is itself a one-dimensional array (an array of arrays). With fixed-size arrays, all elements can be allocated contiguously regardless of how many dimensions there are. Fixed size arrays can be allocated both statically (when the size is known at compile time) or dynamically (when the size is unknown at compile time). However with large arrays it is often necessary to divide the array into smaller subarrays each of which is allocated separately (non-contiguously with each other) and maintain a separate array of pointers to keep track of each of those subarrays. Although this consumes more memory than a contiguously-allocated array would, it has the added benefit in that each subarray need not be the same length, thus it can actually save memory overall. However, if we had several such arrays then we would need yet another array in order to keep track of them all, and this array would need to be an array of pointers to pointers.


It is not possible to declare a two-dimensional array using an array of pointers in any programming language, but many programming languages support declarations of N-dimensional arrays of pointers.The exact syntax varies with the programming language, and requires support for N-dimensional arrays and pointers. In C, the following declares an array of pointer variables, each implemented as pointer to the generic type "void":void* array_1D[10];The type of the expression array_1D is "void * const."The following example expands on the previous one by declaring a two-dimensional array of "void" pointers:void* array_2D[10][20];The type of the expression array_2D is "void ** const."The last example declares a 3-dimensional array of "void" pointers, which can be seen as a 2-dimensional array of arrays of pointers:void* array_3D[10][20][30];


C-style static array: int x[10][5]; // an array of arrays (10 arrays of 5 elements each) C++ static array: std::array<std::array<int, 5>, 10> a; C++ dynamic array (vector): std::vector<std::vector<int>> v; In a C++ dynamic array, each dimension can have a different number of elements. A classic example of a multidimensional array is an array of strings, where each string is a character array of variable length: std::vector<std::string> s;


Arrays are implemented as pointers in c.


Numeric array has numbers(+integers) that represent the values Associative array has strings that represent the values


If the array is static you can simply point at the first element. For dynamic arrays you can allocate a contiguous block to a single pointer which can then be subdivided using a one-dimensional array of pointer to pointers, each of which points to a one-dimensional array of pointers, each of which points to a separate object within the array. For extremely large arrays, however, it is better to split the elements into separate one-dimensional arrays, by creating a one-dimensional array of pointer to pointers first, then allocating each of those pointers to a separate one-dimensional array of pointers, each of which points to a separate one-dimensional array of objects. Either way, you must destroy all the individual arrays in the reverse order of creation.


An array is a collection of objects of similar data type ,whereas pointers are variable which is used to hold the address of the other variable.


An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i ... then *b[0] would be the same as a[0], etc.


Yes. For example, argv parameter of function mainis a pointer to an array of pointers to characters.



The declaration of an array of 3 int pointers will be: int *p[3]; The declaration of a function that receive an array of int pointers will be: int my_func(int **p); or int my_func(int *p[]); and you can pass it to other function simply by passing p.


An array of pointers is exactly what is says on the tin - an array which contains pointers to memory addresses.If you were to create an array of ten integers like this:int array[10];This would create an array which you could directly access from the stack (memory allocated to the program by the Operating System).However, if you wanted to create an array of pointers to integers, allowing for a more efficient use of memory, you could do this:int *array = new int[10];This dynamically allocates an array of 10 pointers to integers.Comment:This example is hardly an efficient use of memory. Not only are you declaring 10 integers, you are declaring a pointer, which uses slightly more memory than would otherwise be required by the first example. An array of pointers is more useful when the memory they point to is non-contiguous and the number of elements is dynamic rather than static. Even dynamic multi-dimensional arrays can be allocated in contiguous space and simple pointer arithmetic can be used to access any element, thus only one pointer is required for the entire array rather than separate arrays of pointers and pointer-to-pointer arrays for each dimension. While pointer arrays can often improve performance, it is always at the expense of memory consumption.


Yes, a linked list can be implemented in an array. Instead of pointers (or references in JAVA) you can use element indexes in the "next" and "last" items.This does not stop you from using pointers or references. They still work. You can take the address of an element of an array, such as &a[217], and place that in the .next or .last pointers, and manage the relationships in the normal way. Using an array is simply one way to manage memory.