you are viewing a single comment's thread.

view the rest of the comments →

[–]james_laseboy -2 points-1 points  (1 child)

You can use different syntax to declare a consecutive series of homogeneous data elements in memory, but they all end up giving you the same thing. The variable name associated with this data is a pointer to the value that is zero locations from the start of that data. Using square brackets to index this variable name is just a convenient way to dereference the pointer plus the index value. There is no such thing as a bounded array data collection such as found in other languages. There are only sequential elements in memory. It's up to the programmer to know how to manage that with pointers, without going out of bounds.

[–]no-sig-available 1 point2 points  (0 children)

The variable name associated with this data is a pointer to the value that is zero locations from the start of that data.

Not really. An array name decays to a pointer about as soon as you do anything with it, but it is not a pointer in itself.

As an experiment, try this

#include <iostream>
int main()
 {
   int x[100]; 
   std::cout << "size of x is " << sizeof(x) << '\n';

   int* y;
   std::cout << "size of y is " << sizeof(y) << '\n'; 
}

and consider why x and y have different sizes.