If I have an array of only one element, we can say it is the same as a pointer. But how's an array of size zero represented in the memory?
What is happening when I declare a variable int * table[0]
?
If I have an array of only one element, we can say it is the same as a pointer
No we cannot. Arrays and pointers are different types and they are represented differently internally. This is true regardless of the array size. Now it is also true that in certain situations (most of the situations actually) an array decays to a pointer to it's first element.
Arrays of size 0
are illegal as per standard, however some major compilers like gcc allow them as an extension.
Read this question to see the difference between internal representations of arrays and pointers: Difference between dereferencing pointer and accessing array elements
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