+ 2

How to check for an empty array?

how can i check whether an array is empty .

24th Jun 2019, 5:05 AM
Deepak Chekuri
13 Answers
+ 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
24th Jun 2019, 7:49 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 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.
24th Jun 2019, 9:19 AM
Manoj
Manoj - avatar
+ 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.
24th Jun 2019, 5:12 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
are talking about the elements or size of the array???
24th Jun 2019, 7:38 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
you don't need to return address of a variable, what for???
24th Jun 2019, 7:56 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 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.
24th Jun 2019, 7:46 AM
Deepak Chekuri
0
Is it possible to return 0 by declaring an array but not filling it
24th Jun 2019, 5:15 AM
Deepak Chekuri
0
How can I pass address of a variable to a function and return the address of another variable (on which operations are performed )
24th Jun 2019, 7:55 AM
Deepak Chekuri
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.
24th Jun 2019, 8:04 AM
Deepak Chekuri
0
Is there any better solution ,I'm welcome to hear
24th Jun 2019, 8:05 AM
Deepak Chekuri
0
Explain your problem properly. What you will initialise then input and expected output
13th Nov 2022, 11:01 AM
Om Yele
Om Yele - avatar