In this code
std::vector<int> vec;
for (int i = 0; i < vec.size() - 1; i++) {
std::cout << "Print" << std::endl;
}
Though vec has no input members so the for loop should not execute at all since "i" will be more than the the condition for execution which is vec.size() – 1
But still the loop is executing.
>Solution :
vec.size() returns an unsigned type. Now vec.size() is 0, but vec.size() - 1 will cause an wrap around, so that’s why you see
std::cout << "Print" << std::endl;
executed