why does this code below give the correct output
#include <iostream>
#include <string>
using namespace std;
int main()
{
int max=0;
string k ="hello";
if(k.length()>max){
    max = k.length();
}
    cout<<max;
}
but this code below doesn't?
#include <iostream>
#include <string>
using namespace std;
int main()
{
int max=-1;
string k ="hello";
if(k.length()>max){
    max = k.length();
}
    cout<<max;
}
 
     
     
    