What is the difference between pointer to vector and pointer to variable?

Asked

Viewed 2,537 times

4

int A;
int* pA = 1;
int Vect[2] = {1,2};
int* pVect;

pA = &A;
*pA = 2;

pVect = Vect;
pVect[0] = 10;

In the case I have a pointer to a variable and then to an array, and I want to change its values by pointer. Why is there this divergence in passing addresses (in the variable I have to use the & and the vector does not need)? This is typical of the C language?

From what I know of pointer, it points to the memory address of that variable obtained by &, but for vector does not need the &.

1 answer

6


If you consider that a vector is a variable, at this point there is no difference.

A pointer points to a point memory address. The address can be obtained in several ways. One of them is a pointer to a vector. You can access a vector by a pointer in a natural way. The variable that accesses a vector is a pointer. Being a pointer has no reason to use the operator’s "address" (&).

See more:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.