I’m trying to fit 16 hex values into an unsigned long long in visual C
unsigned long long test = 0x1A2A00DABABA7890;
printf("long long value %X\n", test);
printf("%d", sizeof(test));
My output shows it is 8 bytes but only storing the first 4 bytes as
it outputs
long long value BABA7890
8
Am I misunderstanding how this works? Thanks for any help.
Your
printfformat specifier doesn’t match your type, which causes undefined behaviour. Try:%dis the wrong format for asizeofresult too. You should be using%zuthere.Your compiler may warn you if you turn up some warning settings (
clangdoes by default, for example):Edit: I notice in your question that you’re using Visual C.
%zis a C99 feature and might not be supported by your compiler. In that case you should check the documentation to see the right format to use.