I was trying the function max()
using visual-studio 2022 Version 17.7.1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
cout << max("5", "4") << "\n";
return 0;
}
and the Output is :
4
and when I change the code to :
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
cout << max("4","5") << "\n";
return 0;
}
the Output is :
5
but when I am using codeblocks :
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
cout << max("5", "4") << "\n";
return 0;
}
and the Output is :
5
and when I change the code to :
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
cout << max("4","5") << "\n";
return 0;
}
the Output is :
4
So visual-studio 2022 Version 17.7.1 choose the second parameter every time and codeblocks choose the first parameter every time ( I guess that ) but Why ? is that because the parameters is converted to const char*
so the comparison every time ( in both visual-studio 2022 Version 17.7.1 and codeblocks ) is between two pointers so it is between two addresses ?