number of elements in a static array of a predefined size

Posted by cppb on Stack Overflow See other posts from Stack Overflow or by cppb
Published on 2010-05-17T03:49:38Z Indexed on 2010/05/17 4:00 UTC
Read the original article Hit count: 218

Filed under:
|
|

I have an array like this:

int a[100]; 

I am filling only the first 4 elements in this array:

a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;

When I do sizeof(a)/sizeof(a[0]) it returns 100.

Is there a way I can get number of elements to which I have assinged a value and thus filtering out the remaining 96 unassigned elements?

thanks

© Stack Overflow or respective owner

Related posts about beginner

Related posts about c++