These are two of probably many ways to declare arrays (and allocate memory for them) in C ++
1. int a[3];
2. int *b = new int[3];
I want to understand how C ++ handles two differently.
and. In both cases, I can access the array with the following syntax: a[1]andb[1]
b. When I try cout<< aand cout<< b, both print the addresses of the first element of the corresponding arrays.
It seems to me that both a and b are considered as pointers to the first elements of arrays.
with. But oddly enough, when I try to do cout << sizeof(a)and sizeof(b), they print different values - 4 and 12. respectively.
I do not understand why in the case the sizeof(b)size of the entire array is printed.
source
share