answersLogoWhite

0

Is there a difference between an array and a pointer?

Updated: 8/17/2019
User Avatar

Wiki User

15y ago

Best Answer

Array is a data type which can be represented as a[1],a[2],a[3].... Pointer is also a data type. The speciality of pointer is instead of address of the variable it will give the reference to the address of the variable. E.g. int *test Here test is a pointer variable. which will be the reference to the address == One dimensional arrays are constant pointers, you cannot change their values, eg: int a[10], *pa = &a[3];

p[0]= a[0]; // ok

a[0]= p[0]; // ok

p= a; // ok

a= p; // INVALID for a is constant

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is there a difference between an array and a pointer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Passing an array name to a pointer assigns the first memory location of the array to the pointer variable?

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.


What is a pointer in 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 ...}


What is the difference bw function pointer and function of pointer?

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.


Why you use an array of pointer to pointer?

because u freakin can


Which two pointer does not increment or decrement in arithmetic array?

constant pointer and character pointer


Why can't we increment an array like a pointer?

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


What is the difference between null array and an empty array?

There is no null array as such. However, a pointer to an array may be nullified (pointing to zero) before memory is allocated to it, or after that memory is released. But the same is true of any pointer. That is, the pointer is NULL, not what it previously pointed to. An empty array usually refers to a dynamic array for which no memory has yet been allocated (in other words, a null pointer). However, the term can also apply to static arrays or dynamic arrays that have been allocated memory, where every element is initialised with a value that has no significance. For instance, an array of natural numbers (positive integers greater than 0) might be initialised with the value 0 (a non-natural number) in every element to indicate that the array is empty. By contrast, individual elements could be set to zero to indicate which elements are available (an empty element as opposed to an empty array).


How do you return an array from function?

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


Difference between pointer to constant and constant pointer?

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.


How do you convert from array notation to pointer notation?

In the C and C++ languages the array notation arr[i] is completely equivalent to the pointer notation *(arr + i).


What is the relationship between an array and a pointer?

All variable names are an alias for the value stored at the memory address allocated to them. To get the memory address itself, you must use the address of operator (&). The value returned from this can then be stored in a pointer variable.Arrays are different. The array name is an alias for the start address of the array, thus you do not need the address ofoperator to obtain the memory address (although you can if you want to). This means that when you pass an array name to a function, you pass the memory address of the array rather than passing the array itself (which would require the entire array to be copied, which is a highly inefficient way to pass an array). In essence, the array is passed by reference rather than by value.Consider the following code. This shows how a primitive variable name differs from the name of an array of primitive variables. The final portion shows how a pointer can be used to achieve the same results you got by accessing the array elements directly from the array name itself. This is in fact how the compiler implements arrays, using pointers, but there's no need to do this in your code. Accessing array elements directly by their index is a programming convenience.#include using namespace std;int main(){int i = 10;cout


What is pointer to a structure?

A pointer is a variable that holds address information. For example, in C++, say you have a Car class and another class that can access Car. Then, declaring Car *car1 =new Car() creates a pointer to a Car object.. The variable "car1" holds an address location.