+ 2
How to check for an empty array?
how can i check whether an array is empty .
11 Respostas
+ 3
Deepak Chekuri as you have said they will definitely be garbage values in it, so I don't think they is a way around that, maybe if you check if the values are zeros, and if non-zero is meet then the array is not empty
+ 13
✓to check whether an array is empty or not just iterate the elements of the array and compare them with null character '/0'.
✓you can also declare an empty array like this arr[]={}. Then use the sizeof function, if it returns 0 your array is empty.
✓if you're declaring an array but not filling it you need to specify the index (or number of elements it can store).
✓ to access the address of the base element of an array you can use &arr[0] or arr.
+ 3
If your array is of zero size it's useless.
Else if you mean arrays that are instantinated but don't have values yet, you can check the array contents. If I am not mistaken it will be filled by either nulls or the default value of the type.
+ 2
are talking about the elements or size of the array???
+ 2
you don't need to return address of a variable, what for???
+ 1
Elements .....
I know that ,by default there are garbage values in arrays but if there is any chance of checking there are no elements...
I've declared the array but not intialized it.
0
Is it possible to return 0 by declaring an array but not filling it
0
How can I pass address of a variable to a function and return the address of another variable (on which operations are performed )
0
Actually my program have to accept two equal sized arrays from two different functions and perform subtraction on these arrays using another function.
I'm trying to get the addresses at where the arrays are stored. So that I can perform subtraction.
0
Is there any better solution ,I'm welcome to hear
0
Explain your problem properly. What you will initialise then input and expected output