Блог пользователя Vinayaka2000

Автор Vinayaka2000, история, 19 месяцев назад, По-английски

Hello codeforces, I'm trying to execute the below piece of code but for some reason, it's getting into an infinite loop and causing a TLE. Please let me know why this is exactly happening ?

#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> v;
    for(int i=0; i<v.size()-1; ++i) {
        cout << " inside " << endl;
    }
}

Ideally, the size of the vector should be zero and in the for loop, 0<(0-1) must be false and the for loop must not execute. When I use the below code, its not executing the for loop. I'm sure it's not because of precedence of < over -.

#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> v;
    for(int i=0; i<0-1; ++i) {
        cout << " inside " << endl;
    }
}

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится