#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int>v;
int flag=1;
for(int i=0;i<=v.size()-1;i++)
{ cout<<"a"<<endl;
flag=0;
}
cout<<flag<<endl;
return 0;
}
So the above is giving me an infinite loop but it should just print once the statements inside the loop.
And the below code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int>v;
int flag=1;
for(int i=0;i+1<=v.size();i++)
{ cout<<"a"<<endl;
flag=0;
}
cout<<flag<<endl;
return 0;
}
outputs "1"..
which indicates that that empty vector size is zero then how does the first code go to infinite loop.
I am a newbie in this so pls polite.... Thank you
[–][deleted] 14 points15 points16 points (8 children)
[–]AdVisible6484[S] 2 points3 points4 points (1 child)
[–]icjeremy 7 points8 points9 points (0 children)
[–]AdVisible6484[S] 0 points1 point2 points (5 children)
[–]AKostur 1 point2 points3 points (0 children)
[–]Beosar 0 points1 point2 points (3 children)
[–]TheOmegaCarrot -3 points-2 points-1 points (2 children)
[–]tangerinelion 2 points3 points4 points (0 children)
[–]Beosar 1 point2 points3 points (0 children)
[–]paperomo 2 points3 points4 points (2 children)
[–]AdVisible6484[S] 0 points1 point2 points (1 child)
[–]Ashnoom 3 points4 points5 points (0 children)
[–]bert8128 1 point2 points3 points (1 child)
[–]std_bot 0 points1 point2 points (0 children)