There is an integer vector inorder
to which I have pushed 5 elements. The variable (int) pointer
has a value -1
. Declared as:
vector<int> inorder;
int pointer;
When I execute the following statement, it gives a false.
cout << (pointer < inorder.size()-1);
However, when I change the statement to the following, it gives a true:
cout<< (pointer+1 < inorder.size());
Why is this happening? The size of the vector is 5, so the problem of (0-1) leading to a very large value should not be there.
EDIT: adding the code to reproduce the issue:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
vector<int> inorder;
inorder.push_back(1);
inorder.push_back(2);
inorder.push_back(3);
int pointer = -1;
cout<<(pointer < inorder.size()-1)<<endl;
cout<<(pointer+1 < inorder.size());
return 0;
}