Back to Blog Home

How To Get Size Of Array In C

Rahul Bansal| C | 6 months, 1 week



 

sizeof operator in C is used for finding the size of array in bytes. This can be used to find the number of elements in array by dividing it by size of single element. 

 

For example 

 

int x[20];  #defines an array with 20 elements
size n = sizeof(x)/sizeof(x[0]);

 

We divide the size of x by size of 1st element in array to get the size or number of elements.

 



Join 1000+ People Who Subscribe to Weekly Blog Updates

Back to Blog Home