Does the array in c++ have address for each element? Or the array has just one address?
Given an array like:
int a[4];
each of the 4 int in a has its own address (separated by the size of an int on your platform).
The address of a is simply the address of the first int in the array. So you can think of an array as having just one address, that is also the address of the first element. But all the elements of the array have their own address which can be used to refer to the elements. In fact, you can even access the individual bytes of each element, but you should be careful when interpreting what those bytes mean, depending on the data type of the elements.
Each element of an array has own address. Address of an array is the address of it's first element.
int main(int, char**)
{
int n[10];
if (std::begin(n) == &n[0]) {
std::cout << "equal";
}
else {
std::cout << "not equal";
}
return 0;
}
Output:
equal
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