my question is essentially in the title. I basically found out that in Java &&, an operator acts like a short circuit, so if the first condition evaluates to false, it doesn't consider the rest of the statement. I assumed it was in C ++, but I write some code that first checks that the index has not exceeded the size of the list, and then compares this index in the list with a different number. Sort of:
for(int i=0; i<10; i++)
{
if(i < list.size() && list.get(i) == 5)
...
}
This is not exact code, but it illustrates the point. I assume that since i> is the size of the list, the second half will not be evaluated. But it looks like this is still happening, and I believe that it causes Seg Fault. I know that I can use nested ifs, but it is such an eyesore and a waste of space. Any help?
source
share