This code is from MSDN. So, we have an union, which contains the struct and the variable. In my code I declared the prototype of union and then initialized the "QuadPart" of union. But printing the Quad Part doesn’t give the full number but the LowPart of it. Is it a way it should be?
typedef union _LARGE_INTEGER
{
struct {
unsigned LowPart;
unsigned HighPart;
} u;
unsigned long long QuadPart;
} LARGE_INTEGER;
int main(int argc, char** argv){
LARGE_INTEGER num1;
num1.QuadPart = 0x1020304050607080;
printf("Low: %x, high: %x, quad: %x\n", num1.u.LowPart, num1.u.HighPart, num1.QuadPart);
return 0;
}
I expected the full number displayed by num1.QuadPart
>Solution :
use llx for printing long long type printing in hex format
#include <stdio.h>
typedef union _LARGE_INTEGER
{
struct {
unsigned LowPart;
unsigned HighPart;
} u;
unsigned long long QuadPart;
} LARGE_INTEGER;
int main(int argc, char** argv){
LARGE_INTEGER num1;
num1.QuadPart = 0x1020304050607080;
printf("Low: %x, high: %x, quad: %llx\n", num1.u.LowPart, num1.u.HighPart, num1.QuadPart);
return 0;
}