for calculating the number of elements in an array,how do we do it using sizeof…i didnt get it…sieof(a)/sizeof(int)
total elements in array
Hey Shraddha, this is simple maths, the sizeof operator yields the size (in bytes) of its operand.
For eg.
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int N = sizeof( a ) / sizeof( int );
as every integer takes 4 bytes(this may differ as it is system dependent), so as the array has 10 elements, sizeof( a ) results 40 bytes and size of int is 4.
so sizeof( a ) / sizeof( int ) => 40/4 = 10
Like this by dividing total size by size of one element, we can find the no. of elements in the array