The function sizeof
returns the number of bytes which is used by your array in the memory. If you want to calculate the number of elements in your array, you should divide that number with the sizeof
variable type of the array. Let's say int array[10];
, if variable type integer in your computer is 32 bit (or 4 bytes), in order to get the size of your array, you should do the following:
int array[10];
int sizeOfArray = sizeof(array)/sizeof(int);