vendredi 22 mai 2020

Weird output with vector.size() when empty vector [duplicate]

When I run this bit of code

#include <bits/stdc++.h>

using namespace std;

int main() {
  vector<int> v;
  cout << v.size() << endl;
  cout << v.size() - 1 << endl;
  cout << v.size() - 2 << endl;
  return 0;
}

Output is:

0                                                                                                                
18446744073709551615                                                                                             
18446744073709551614

I am using c++11, can anyone explain this ?

Aucun commentaire:

Enregistrer un commentaire