What is this sizeof trick doing?

Viewed 763

It's been a while since I looked at C code, but I'm trying to make sure I understand what's going on here. Someone has declared this (has more members in their code):

int trysizes[] = { 64, 64, 128, 64, };

Then later they use this as part of a for loop:

sizeof(trysizes)/sizeof*(trysizes)

I'm thinking the first part is the number of bytes in the array and the second part must be the size of each array member giving us the number of items in the array. Is this a standard way to calculate array length and what is the second sizeof actually doing?

3 Answers
Related