Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

How to use sizeof operator to calculate number of elements in array of structures ?

 ParameterDef const  Parameters : : Info[ ] =
{
{ParameterId_Vendor,                                           0,       2,       0,  false,  null}, 
{ParameterId_SystemOverview,                          1,       2,       1,  false,  null}, 
.....

Open in new window



We have large array of structures.  In our code, sizeof operator is used to find number of elements in the array as follows:

sizeof (Parameters : : Info) / sizeof ( * Parameters : : Info )
 
* Parameters : : Info    // is this the size of first element of the array ?

Would the following be equivalent:

sizeof (Parameters : : Info) / sizeof ( Parameters : : Info [ 0 ] )
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naseeam

ASKER

concise and useful macro to find number of elements in an array.