120,977 views
9 votes
9 votes
How do I determine the size of my array in C?

User Rahul Bansal
by
2.7k points

1 Answer

7 votes
7 votes

Answer:

In C, you can use the sizeof operator to determine the size of an array. For example, if you have an array named myArray, you can determine its size with the following code:

int arraySize = sizeof(myArray) / sizeof(myArray[0]);

Step-by-step explanation:

This will give you the number of elements in the array. Keep in mind that sizeof returns the size of the array in bytes, so you need to divide by the size of a single element in the array (which is given by sizeof(myArray[0])) to get the number of elements.

User Source
by
3.1k points