如何使用 printf 格式化 unsigned long long int? [英] How do you format an unsigned long long int using printf?

查看:115
本文介绍了如何使用 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.
", 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 (el-el) long-long 修饰符与 u(无符号)转换一起使用.(适用于 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆