3 ms·
I think a better way to think about is to say that when you type: int a[10]; you allocate 10 integers and "a" is the pointer to the first one of them. Arrays
by quelsolaar 6y ago
I think a better way to think about is to say that when you type:
int a[10];
you allocate 10 integers and "a" is the pointer to the first one of them.
Arrays are just memory, just like what you get wen calling malloc, and memory is accessed using pointers in C.
- rightbyte 6y agoThat mindset doesn't cover sizeof(a) properly.
- quelsolaar 6y agoI agree, that's an inconsistency I would rather fix, then the one OP suggests.
- Cyph0n 6y agoMinor nitpick: there is no allocation going on here - you’re simply reserving a fixed-size buffer on the stack (assuming the array is local to a function).
- quelsolaar 6y agoI would call that a stack allocation, but yes they are slightly different. In my mind its a feature that arrays allocated on the stack and heap can interchangeably be given as an argument to a function.
- jstimpfle 6y agoTo allocate means to get or reserve something (for lack of an even better word, as a non-native). This is a perfectly valid use of allocation. What you mean is maybe more aptly named "dynamic (memory) allocation".