#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, abcWhy could have been this behaviour!! :(
Using incorrect format specifier in printf invokes Undefined Behaviour. The correct format specifier for long long
is %lld
.
Also make sure that you dont have signed integer overflow in your code because that's UB too.
You should use printf("%llx, %llx, abc\n", x, y);
in my mind. %lx
for long integer.
精彩评论