Why does this result run into infinite loop?
After entering the for
loop, I printed values of i
and v.size()-2
and they are 0
and -1
respectively. Hence, the loop condition must be false
. Then, how does this program get into the for
loop in the first place?
#include <iostream>
#include <vector>
int main() {
std::vector<int> v {1};
std::cout << "Size:: " << v.size();
for (int i=0 ; i <= (v.size()-2) ; i++) {
std::cout << "Hello";
}
return 0;
}