0

Why is static_cast not working and giving unexpected results in this code?

#include <iostream> using namespace std; int main() { int a{1}; int b{4}; unsigned int temp{}; temp = static_cast<unsigned int>(a-b); cout << temp; return 0; } In this code I want to get absolute difference of a and b using static_cast but it's not working and give same garbage answer in my pc terminal and in sololearn

22nd Aug 2021, 6:35 PM
karangreat
1 Réponse
0
Martin Taylor could u please tell me why static cast works for int to double conversion but not for signed int to unsigned int?
29th Aug 2021, 5:02 AM
karangreat