I m getting an unexpected output for the following code :
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
vector <string> d ;
d.push_back("hh") ;
d.push_back("jj") ;
int index = -1 ;
if ( index < d.size() )
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}
The output I get is : NO ( even though index < d.size() )
but when I replace these line from my code :
if ( index < d.size() )
cout<<"YES"<<endl;
with the lines below
int len = d.size() ;
if ( index < len )
cout<<"YES"<<endl;
This time the output is as expected : YES
here is the new code which gives expected output :
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
vector <string> d ;
d.push_back("hh") ;
d.push_back("jj") ;
int index = -1 ;
int len = d.size() ;
if ( index < len )
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}
what is reason for the unexpected result I got in the first code ??