answersLogoWhite

0


Best Answer

An array's name is not a constant pointer; it's not even a pointer! An array name is a reference to the array itself. Unlike pointers, references have no memory of their own, therefore a reference cannot be constant (only what it refers to can be constant). A reference is nothing more than an alias for a memory address. Since there is no separate storage for references, you cannot reassign references while they remain in scope. So, in that sense, it behaves like a constant pointer. But a pointer is a variable, so even if declared const, it requires memory of its own in order to store the memory address it points to.

Example:

int a[10];

int * const p = a; // const pointer

assert( *p &a ); would cause an assertion. Likewise, assert( p != &p); proves that p must reside in a separate memory address from that referred to by a. It has to: pointers are variables even when they are declared const.

User Avatar

Wiki User

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

Wiki User

14y ago

Yes, we can see it that way.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: An array name is a pointer constant?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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

constant pointer and character pointer


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.


Does mentioning the array name gives the base address in all the contexts?

Mentioning the array name in C or C++ gives the base address in all contexts except one. Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even mix the usages within an expression. When you pass an array name as a function argument, you are passing the "value of the pointer", which means that you are implicitly passing the array by reference, even though all parameters in functions are "call by value". There is, however, one very important distinction. While an array name is referentially the same as a pointer, it is not a pointer in that it does not occupy program referential space in the process. This means that, while you can change the value of a pointer, and thus the address to which it points, you can not change the value of an array name. This distinction is what we call R-Value (array or pointer) as opposed to L-Value (pointer only), i.e. can the object appear on the left sign of an assignment operator.


What is array passer c plus plus?

//Array Passer //Demonstrates relationship between pointers and arrays #include <iostream> using namespace std; void increase(int* const array, const int NUM_ELEMENTS); void display(const int* const array, const int NUM_ELEMENTS); int main() { cout << "Creating an array of high scores.\n\n"; const int NUM_SCORES = 3; int highScores[NUM_SCORES] = {5000, 3500, 2700}; cout << "Displaying scores using array name as a constant pointer.\n"; cout << *highScores << endl; cout << *(highScores + 1) << endl; cout << *(highScores + 2) << "\n\n"; cout << "Increasing scores by passing array as a constant pointer.\n\n"; increase(highScores, NUM_SCORES); cout << "Displaying scores by passing array as a constant pointer to a constant.\n"; display(highScores, NUM_SCORES); return 0; } void increase(int* const array, const int NUM_ELEMENTS) { for (int i = 0; i < NUM_ELEMENTS; ++i) array [i] += 500; } void display(const int* const array, const int NUM_ELEMENTS) { for (int i = 0; i < NUM_ELEMENTS; ++i) cout << array[i] << endl; }


How do you return an array from function?

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

Related questions

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

constant pointer and character pointer


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.


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


Does mentioning the array name gives the base address in all the contexts?

Mentioning the array name in C or C++ gives the base address in all contexts except one. Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even mix the usages within an expression. When you pass an array name as a function argument, you are passing the "value of the pointer", which means that you are implicitly passing the array by reference, even though all parameters in functions are "call by value". There is, however, one very important distinction. While an array name is referentially the same as a pointer, it is not a pointer in that it does not occupy program referential space in the process. This means that, while you can change the value of a pointer, and thus the address to which it points, you can not change the value of an array name. This distinction is what we call R-Value (array or pointer) as opposed to L-Value (pointer only), i.e. can the object appear on the left sign of an assignment operator.


When does an array behave a pointer?

An array behaves like a pointer when you use its name in an expression without the brackets.int a[10]; /* a array of 10 ints */int *b = a; /* a reference to a as a pointer, making b like a */int c = *(a+3); /* a reference to a[3] using pointer semantics */myfunc(a); /* pass a's address, a pointer to myfunc */Note very carefully that, while an array name and a pointer can almost always be interchanged in context, the are not the same, in that a pointer is an l-value, such as b, above, and can be assigned, whereas a is an r-value and can only be referenced, such as in the same statement, the second statement. Also, an array name does not take up memory, while a pointer does.


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 the pointers is used with arrays?

A pointer can point to any element of the array, the array itself is a constant pointer. Eg.: int a[10], *p; p= &a[3]; p= a; /* the same as p= &a[0] */ a[2]= *p; a[3]= p[4]; a= p; /* WRONG! */


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


Why you use an array of pointer to pointer?

because u freakin can


Why pointer can't be added in computer language C?

You can add a point in C/C++. The legal operations on a pointer are that you can 1.) add a constant, 2.) subtract a constant, and 3.) subtract two pointers that refer to the same array. Anything else is meaningless.


What is array passer c plus plus?

//Array Passer //Demonstrates relationship between pointers and arrays #include <iostream> using namespace std; void increase(int* const array, const int NUM_ELEMENTS); void display(const int* const array, const int NUM_ELEMENTS); int main() { cout << "Creating an array of high scores.\n\n"; const int NUM_SCORES = 3; int highScores[NUM_SCORES] = {5000, 3500, 2700}; cout << "Displaying scores using array name as a constant pointer.\n"; cout << *highScores << endl; cout << *(highScores + 1) << endl; cout << *(highScores + 2) << "\n\n"; cout << "Increasing scores by passing array as a constant pointer.\n\n"; increase(highScores, NUM_SCORES); cout << "Displaying scores by passing array as a constant pointer to a constant.\n"; display(highScores, NUM_SCORES); return 0; } void increase(int* const array, const int NUM_ELEMENTS) { for (int i = 0; i < NUM_ELEMENTS; ++i) array [i] += 500; } void display(const int* const array, const int NUM_ELEMENTS) { for (int i = 0; i < NUM_ELEMENTS; ++i) cout << array[i] << endl; }