79302400

Date: 2024-12-23 07:12:16
Score: 1
Natty:
Report link

It seems like you're working with a 2D array, but in C++, all rows in a traditional 2D array have the same number of elements, even if you try to initialize them with different lengths. This is why your sizeof operation is returning 6, as it is treating each row as if it has 6 elements, as per the declaration.

To achieve a solution where the rows have different lengths (a "ragged" array), a 2D array is not the best choice in C++. Instead, you could use a dynamic data structure like std::vectorstd::vector<int>, which allows each row to have a different number of elements.

This way, you can easily get the size of each row by calling .size() on the inner vector, which will return the actual number of elements in that row, regardless of how many columns you initially declared.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: blackhole