These two arrays have the same size and elements:
int list[] = {1,2,5,2,5,2,5,2,};
// ^ extra comma
int size1 = sizeof(list)/sizeof(list[0]);
int list2[] = {1,2,5,2,5,2,5,2};
int size2 = sizeof(list2)/sizeof(list2[0]);
std::cout << "size1: " << size1 << " size2: " << size2 << "\n"; // size1: 8 size2: 8
- So, are they completely the same ?
Why is that extra comma allowed? I get it can be practical whe you copy-paste arrays like
someComplicatedStruct list3[] =
{ {1,5,3},
{1,2,9},
{1,2,6},
{7,2,3},
// ^ Is this actually usefull?
};
But it seems risky, if it is, why is this allowed?