相关疑难解决方法(0)

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

#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;
}
Run Code Online (Sandbox Code Playgroud)

输出:

My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
Run Code Online (Sandbox Code Playgroud)

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

c syntax printf format-specifiers long-long

356
推荐指数
8
解决办法
73万
查看次数

标签 统计

c ×1

format-specifiers ×1

long-long ×1

printf ×1

syntax ×1