如何使用printf格式化unsigned long long int? [英] How do you format an unsigned long long int using printf?
本文介绍了如何使用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;
}
输出:
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
?
I assume this unexpected result is from printing the unsigned long long int
. How do you printf()
an unsigned long long int
?
推荐答案
在ll(无符号)转换中使用ll(el-el)long-long修饰符.(可在Windows中运行,GNU).
Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).
printf("%llu", 285212672);
这篇关于如何使用printf格式化unsigned long long int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文