+ 1
Why is this possible?
I'm currently learning C++ and I've been told many many times that arrays need to have their lengths stated at instantiation, but when I was in the code playground, this worked: int myArr[] = {1, 2, 3}; cout << sizeof(myArr); The output was 12 since each int takes up 4 bytes and theres 3 of them, so that makes sense to me, but why can I create this array without stating the length between the brackets?
1 Odpowiedź
+ 2
In this case, the compiler will determine the size of the one-dimensional array itself. The size of the array can be omitted only when it is initialized; with the usual declaration of an array, the size of the array must be specified