For example, I have this declaration :
int a[10];
Before, I understood it like this: a
in fact is a pointer, and it will point to 10 elements consecutively in memory.
But today, when my teacher taught me, he said: it will be an array of pointers, and each pointer points to its value.
I don't know which is true. please tell me.
Before, I understand like this : a in fact is a pointer, and it will points to 10 elements consecutively in memory.
This is wrong, it is an array. It has a specific location in the memory and can hold 10 integers. With a pointer you can do a = &some_int
, however, this does not work for arrays. If you pass a
to a function that is expecting a pointer, it will be decayed (converted into) a pointer but this is different.
But, today, when my teacher tauch me, he said : it will have an array of pointer, and each pointer point to its value.
This is also wrong, it is an array of 10 integers. To have 10 integer pointers, you need to define it as int *a[10]
. Still elements do not point to their values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With