小编典典

如何使用 printf 格式化 unsigned long long int?

all

#include <stdio.h>
int main() {
    unsigned long long int num = 285212672; //FYI: fits in 29 bits
    int normalInt = 5;
    printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
    return 0;
}

输出:

My number is 8 bytes wide and its value is 285212672l. A normal number is 0.

我认为这个意想不到的结果来自打印unsigned long long int. 你怎么printf()一个unsigned long long int


阅读 130

收藏
2022-03-21

共1个答案

小编典典

将 ll (el-el) long-long 修饰符与 u(无符号)转换一起使用。(适用于 Windows,GNU)。

printf("%llu", 285212672);
2022-03-21