In depth analysis of the C language constant data types

  • 2020-04-02 01:45:47
  • OfStack

Without further ado, go to code


//Compile environment: codeblocks+ GCC
#include <stdio.h>
#include <stdint.h>
int Fun()
{
    uint64_t y;
    uint32_t x1, x2;
    //y = 3000 * 24000000 / 1000;// The constant defaults to 32 Bit data, temporary results are also 32 Bit, overflow error 
    //y = (uint64_t)3000 * (uint64_t)24000000 / 1000;// Constant cast to 64 Bit, correct 
    y = 3000ULL * 24000000ULL / 1000ULL;//The constants are in 64 bit format and the operation is correct

    printf("0x%llXn", y);//The output
    x1 = (uint32_t)(y & 0xFFFFFFFF);
    x2 = (uint32_t)(y >> 32);
    printf("0x%X,0x%X n", x1, x2);//The output The results of 
}
int main()
{
    Fun();
}


Related articles: