answersLogoWhite
Computer Programming
C Programming
C++ Programming

Difference between pointer and array?

345

Top Answer
User Avatar
Wiki User
Answered
2012-01-09 13:58:20
2012-01-09 13:58:20

pointer is use to hold address of another variable whereas array is a collection of elements of similar datatype

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

Related Questions


Pointer holds an address Array holds values


--> Array is a collection of same kind of data.--> Pointer is a memory location where the data stored in the memory


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 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.


difference between pointer or structure


Yes, passing an array name to a pointer assigns the first memory location of the array to the pointer variable. An array name is the same as a pointer to the first location of the array, with the exception that an array name is a r-value, while a pointer is an l-value.


yes.. an array can be accessed through pointer


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.


A pointer into an array of elements of type E is a pointer to a single element of type E:typedef ..... E;E array[123];E* const pointer = &array[18]; // points to the 19th element inside 'array'An array of pointers is an array whose elements are pointers:typedef .... E;E* array[123];E** const pointer = &array[18]; // points to the 19th pointer within 'array'Referencing the name of the array variable without use of the index operator itself is a constant pointer to its first element. Therefore, the following if-clause is always true:typedef .... E;E array[123];if (array &array[N]) { // ALWAYS true ...}


Array name is a static pointer to the array.Meaning of static here is that we can not modify the pointer (array name) value to any other value. Array name is the base address of the array in memory. for example if we have array a[5] of float starting at address 1000 in memory then a tells us the base address of array or address of a[0] i.e. 1000. a+1 tells the address of element a[1] and so on. we can access the element of an array by considering the array name as pointer. *(a+2) will access the third element of an array a i.e. a[3]. but we can't achieve it by applying ++ operator 3 times since the array pointer can't be modified.


array and pointer both are derived datatypes..


An array can be regarded as a constant pointer, example: int a[10], *p; p= a; p[1]= a[1]; *a= *p; /* all okay */ a= p; /* WRONG */


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.



function pointer is a variable that hold the address of any function which declared in the program but function pointer is the array of the function that accept the run time size of the function.



char c[3]; //array of 3 chars char * p; //pointer of type char p=c; //point the pointer to the base of char array


You point at the array the same way you would with an array of any pointer type, by using an additional level of indirection than is employed by the pointers in the array itself. In this case, the array contains pointer-to-function data types (with one level of indirection), thus you must use a pointer-to-pointer-to-function data type (with two levels of indirection) in order to point at the array itself. Had the array contained pointer-to-pointer-to-function data types (where each pointer points to a separate array of pointer-to-function data types), then you'd use three levels of indirection, and so on. You increase the level of indirection by placing an additional asterisk before the pointer's name when you declare the pointer. That is, one asterisk per level.



once we initialize the array variable, the pointer points base address only & it's fixed and constant pointer


A pointer is a variable that may contain a memory address, or NULL (zero). An array is collection of data, usually residing in a contiguous block of memory, where every element is accessed as an offset from the beginning of the array.


A pointer is a variable like any other. As such, it has memory allocated to it. It is similar to an int in that they both store a value in their memory location. However, whereas an int value is interpreted as a whole number, a pointer's value is interpreted as a memory address. The pointer is said to "point to" the memory address it contains. The type of the pointer determines the type of the variable stored at that memory address. the following is a declaration of a pointer to an integer initialised with the value zero: int * p = new int(0); A pointer to a pointer is no different to an ordinary pointer, except the memory address it points to is that of another pointer. The following is an example of a pointer that points to the pointer we've just declared. int ** pp = p; Pointer-to-pointer variables are typically used whenever you need to pass a pointer by reference. All pointers are passed by value, so the memory address they contain is passed, not the pointer variable itself. To pass the pointer itself, you must pass a pointer to the pointer, which passes the memory address of the pointer. This then makes it possible to change the memory address stored in that pointer. Pointer-to-pointer variables are also used when declaring dynamic, multi-dimensional arrays. For instance, a 2-dimensional array requires a pointer-to-pointer to reference the array itself. This pointer points to a 1-dimensional array of pointers, each of which points to a 1-dimensional array of the actual variables in the array. Unlike a static multi-dimensional array, where the entire array occupies contiguous memory, a dynamic multi-dimensional array may not reside in contiguous memory. Pointer-to-pointer can be extended further to accommodate 3-dimensional arrays, and above. A 3D array requires a pointer-to-pointer-to-pointer, which points to a 1-dimensional array of pointer-to-pointer, each of which references a 2D array, as previously outlined.


1. pointer to a constant means you can not change what the pointer points to 2. constant pointer means you can not change the pointer.


By returning a pointer to the first element of the array.


The former is variable, the latter is constant.



Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.