Find length of the array in C by R4R Team

Array:

Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.

Size of Array:
Total elements*sizeof(one element)

Length of Array:
Formula:
length=sizeof(array)/sizeof(a[i])
-Here a[i] shows the one element of the array.

Example-
Array is {1,2,3,4,5}
Then sizeof(Array) is 20
and sizeof(int) is 4
then length is 20/4=5

program-

#include < stdio.h>
int main()
{
int a[6],b[100],c[500];
printf("Size of first array is %d",sizeof(a)/sizeof(a[0]));
printf("Size of second array is %d",sizeof(b)/sizeof(b[0]));
printf("Size of third array is %d",sizeof(c)/sizeof(c[0]));
}


output-

Size of first array is 6
Size of second array is 100
Size of third array is 500




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!