Answer the question
In order to leave comments, you need to log in
How to check if an array is empty?
Good evening! I don't know how to check if the array is empty or has data. For example, there is this code:
int max(int* tab, unsigned int len)
{
int i;
int tmp;
i = 0;
tmp = tab[i];
while (i != len)
{
if (tmp <= tab[i])
tmp = tab[i];
i++;
}
return (tmp);
}
int main(void)
{
int arr[10];
printf("%i", max(arr, 10));
return (0);
}
Answer the question
In order to leave comments, you need to log in
In the C language, in principle, there are no "empty" arrays. Unless the memory dynamically allocated for an array can have a size of 0, or a flexible array member in a structure can correspond to an array of size 0.
Therefore, it is not clear what you are talking about at all.
In any case, passing the correct array size to such a function is up to you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question