A
A
artemka852016-08-20 09:38:01
C++ / C#
artemka85, 2016-08-20 09:38:01

Array in C + pointer?

In general, thought about the idea.
Here for example I create an array:
int a[3] = {1, 2, 3};
Output : a
Output : &a
and : &a[0] the
same way . hmm.
after all, in fact the variable "a" contains the address of the zero element of the array, right?
it means that this variable "a" was created in memory, or rather a pointer, and it contains the address of the zero element of the array.
but then when outputting :
&a and &a[0] different addresses should be output. so what happens.
compiler hides this variable from us?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Moseychuk, 2016-08-20
@fshp

because in fact the variable "a" contains the address of the zero element of the array, right?

No. As you correctly noted, the name of an array, its address and the address of the first element are the same. There is no additional hidden variable, because you allocate an array in automatic memory (on the stack).

A
Alexey, 2016-08-20
@lehatut1

there in one case just a pointer to the null element.
and in the other case, a reference to a pointer to a null element (a reference to a pointer is essentially the same as a pointer to a pointer).
if the array were dynamic, it would matter in terms of memory allocation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question