How to check array value at specific index

Aug 1, 2013 at 8:06pm
hello everyone, how can I check that value at specific index of an array is empty or not. for example

1
2
3
4
void storeAt( int index,int val)
{
   arr[index] = val //arr[] has been declared in class
}


I can put value only if arr[index] is empty, if already occupied I cannot add value. how can I check arr[index] is empty?
Aug 1, 2013 at 8:07pm
First of all you should define what means an element is empty.
Aug 1, 2013 at 8:09pm
element obviously cannot be empty. im talking about the array's index
Last edited on Aug 1, 2013 at 8:09pm
Aug 1, 2013 at 8:18pm
Read one more what I wrote if you can not understand what I said.
Aug 1, 2013 at 8:20pm
If you meant to check whether an element is equal to some value when you can write

1
2
3
4
bool storeAt( int index,int val)
{
   return arr[index] == val;
}
Topic archived. No new replies allowed.