Find number of elements of the array(using sizeof operator)
For example:
If the given array is
1 2 3 4 5 6
then the number of elements is 6
Implementation:
For example:
If the given array is
1 2 3 4 5 6
then the number of elements is 6
Implementation:
#include <stdio.h> #include <stdlib.h> #include <limits.h> int main(void) { /* Input array */ int a[]={1,2,3,4,5,6}; /* Print the number of elements of the array */ /* sizeof(a) would give 24 bytes */ /* sizeof (*a) would give 4 bytes which is sizeof a single integer */ /* if we divide the total size with individual data size , we get the number of elements */ printf("number of elements in the array is %d",sizeof(a)/sizeof(*a)); return 0; }