How to find length of sub-array

Here is my piece of code:
1
2
3
4
5
6
7
8
    int b[2][2] =
    {
        {4,6},
        {-3,0}
    };
    int b_length = (sizeof b)/sizeof(int);

    int *sub_b = b[1];


b_length will have the length of 2-D array b (4, in this case).
now sub_b is the sub-array of b at row 1, which is {-3,0}
Is there any way to find the length of sub_b other than the below technique.

int sub_length = (sizeof b[1])/sizeof(int);
Yes, because the full array definition of b is visible where you call sizeof from.

You'll have a problem if you pass it to a function as some kind of pointer.
You'll have a problem if you pass it to a function as some kind of pointer

Yes, exactly. That's the same issue i faced when I tried sizeof on sub_b pointer.
My question is, whether there is anyway I could get the size of the sub-array of "b".
For example in Java I can do something like this

int[] sub_b = b[1];
sub_b.length; //gives me the size of the sub-array

But in C++ there seems to be no such option.
Use a vector.
Topic archived. No new replies allowed.