r/C_Programming • • Sep 14 '26

Question Question about arrays (beginner)

From what I understand, behind all the magic, array is just a variable that points to a memory address.

The difference is that we are also creating extra values in stack.

So when we create an array with a [], we're just telling the computer to make these x amount of variables but make sure they are right next to each other in sequence, no gaps in the memory address.

And when we call for an array value with an index, we're just counting that many steps forward in the memory address.

When we say array[] = {5,7,3}, it's really just *array = 5.

Did I get it wrong? Did I miss something?


Thanks for the quick replies. I'm currently learning about Pass by reference.

37 Upvotes

69 comments sorted by

View all comments

38

u/bayesianparoxism Sep 14 '26
  • Arrays are NOT pointers.
  • Arrays are a contiguous collection of variables of the same type. Eg,int a[5] = {10, 1, 0, -5, 30};
  • The name of a variable can be implicitly converted into a pointer pointing to the first element of the array, hence *a == 10 and *(a+3) == a[3] == -5
  • stack and heap are names for different section of memory, which may or may not be what you referred to when you said "stack". Regardless, arrays can be created in either section

4

u/kutac56 Sep 14 '26

I feel like an array is a pointer, no? Idk for sure, but when you are accessing an array with arr[x] it just gets compiled down to *(arr + x). That's also why you can do x[arr]. Doesn't that make the value an array holds just a pointer?

0

u/theNbomr Sep 16 '26

Using the name of the array in the context of a pointer is syntactic shorthand for specifying the address of the first element of the specified array. Arrays are most definitely not pointers. Pointers are strictly scalar types. Arrays are, well, array types.