lundi 7 novembre 2022

Unexpected boolean result with vector size and -1 [duplicate]

In the test

bool test = -1 > vec.size(); 

where vec is a non-empty vector, the value of test is true. Why? How would this be investigated?

  bool test0 = -1 > 10; // false
  // vec.size() = 10
  bool test1 = -1 > vec.size();  // true
  bool test2 = 0 > vec.size();   // false
  bool test3 = 1 > vec.size();   // false
  bool test4 = 11 >= vec.size(); // true

Aucun commentaire:

Enregistrer un commentaire