0

Why does multiset.end() return a different value when compared to vector.end().

int main(){
    multiset<int>v={1,2,3,4,5,6,7,8};
    cout<<*v.end()<<endl;
    return 0;
}

In case of multiset, it returns a value of total elements present in the multiset.

int main(){
    vector<int>v={1,2,3,4,5,6,7,8};
    cout<<*v.end()<<endl;
    return 0;
}

Whereas vector returns 0.

sushi
  • 65
  • 6
  • 4
    Both of these invoke *undefined behavior* when dereferencing an end-iterator. – WhozCraig Apr 06 '22 at 15:48
  • Both of your examples produces a big `assert` dialog box when run using Visual C++ under the debug runtime, all because of the dereferencing of `end()`. Thus nothing got printed. – PaulMcKenzie Apr 06 '22 at 15:53

0 Answers0