You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
long long int charPtrToInt(const char* str)
{
long long int a = (long long int)str;
return a;
}
int main() {
const char* str = "123";
charPtrToInt(str);
}
Output:
long long charPtrToInt(const char * str)
{
long long a = static_cast<long long>(str);
return a;
}
int main()
{
const char * str = "123";
charPtrToInt(str);
return 0;
}
But the conversion from const char* to long long is being accomplished by a reinterpret_cast<long long>, not a static_cast<long long>. If you try to substitute in the static_cast, the code fails to compile.
The text was updated successfully, but these errors were encountered:
See for example https://cppinsights.io/lnk?code=bG9uZyBsb25nIGludCBjaGFyUHRyVG9JbnQoY29uc3QgY2hhciogc3RyKQp7CiAgICBsb25nIGxvbmcgaW50IGEgPSAobG9uZyBsb25nIGludClzdHI7CiAgICByZXR1cm4gYTsKfQoKaW50IG1haW4oKSB7CiAgICBjb25zdCBjaGFyKiBzdHIgPSAiMTIzIjsKICAgIGNoYXJQdHJUb0ludChzdHIpOwp9&insightsOptions=cpp17&std=cpp17&rev=1.0
Source:
Output:
But the conversion from
const char*
tolong long
is being accomplished by areinterpret_cast<long long>
, not astatic_cast<long long>
. If you try to substitute in thestatic_cast
, the code fails to compile.The text was updated successfully, but these errors were encountered: