mercredi 24 juin 2020

what will vector.size()-1 will return when vector is empty? [duplicate]

when a empty vector is created and the following operation is done i am getting wrong answer.

vector.size() - enter code here1 on empty vector its returns 4294967295 but the answer is -1

#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> v;
  cout<<v.size()<<"\n";
  cout<<v.size() -1 <<"\n";
 
}

the expected output should be

0

-1

but what i am getting was

0

4294967295

i don't know what is going wrong, can anyone tell whats wrong and pls correct it

Aucun commentaire:

Enregistrer un commentaire