mardi 22 septembre 2020

Really weird if statement behavior in C++

Only the first statement is printed even though both if expressions should evaluate the same. Why?

    map <int, int> elem;
    vector <int> nums(2);
    int x = 1;
    elem[x]=-1;
    
    int val = elem[x];

    if(val>nums.size()/3) {cout << "First";} // as you can see, vals is -1 and nums.size() is 2
        
    if(-1>2/3) cout<< "Second";

Aucun commentaire:

Enregistrer un commentaire