views:

106

answers:

2

In C, the idea of an array is very straightforward—simply a pointer to the first element in a row of elements in memory, which can be accessed via pointer arithmetic/ the standard array[i] syntax.

However, in languages like Google Go, "arrays are values", not pointers. What does that mean? How is it implemented?

+1  A: 

In most cases they're the same as C arrays, but the compiler/interpreter hides the pointer from you. This is mainly because then the array can be relocated in memory in a totally transparent way, and so such arrays appear to have an ability to be resized.
On the other hand it is safer, because without a possibility to move the pointers you cannot make a leak.

mbq
A: 

Arrays in Go are also values in that they are passed as values to functions(in the same way ints,strings,floats etc.) Which requires copying the whole array for each function call.

This can be very slow for a large array, which is why in most cases it's usually better to use slices

Jessta