The following code
#include <vector>
#include <iostream>
using namespace std;
int main() {
vector<int> value;
cout << value.size() << endl; // output 0
cout << value.size() - 1 << endl; // output 18446744073709551615
}
Why the second output is not -1? What happens at the second cout?
vector::size()
is of type size_t
which is an unsigned type, and unsigned integers can't represent negative numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With