#include <stdio.h>
int main()
{
long long x = 0x8ce4b16b;
long long y = x<<4;
printf("%lx, %lx, abc\n", x, y);
return 0;
}
I’m getting
8ce4b16b, 0, abc… Is this okay?
However if I change printf like printf("%lld, %lx, abc\n", x, y);
The output becomes:
2363797867, ce4b16b0, abc
Why could have been this behaviour!! 🙁
Using incorrect format specifier in printf invokes Undefined Behaviour. The correct format specifier for
long longis%lld.Also make sure that you dont have signed integer overflow in your code because that’s UB too.