C语言 如何在C中用printf打印一个无符号长整数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4033018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:49:10  来源:igfitidea点击:

How to print an unsigned long int with printf in C?

cprintf

提问by alex

Possible Duplicate:
How to printf “unsigned long” in C?

可能的重复:
如何在 C 中打印“unsigned long”?

I have my number like so...

我的号码是这样的...

int unsigned long number = 600851475143;

I am trying to print it with printf(). Every time I try, I get a warning by the compiler.

我正在尝试使用printf(). 每次我尝试时,都会收到编译器的警告。

I've tried %uld, %ldand Googling hasn't seemed to find me the answer.

我试过了%uld%ld谷歌搜索似乎没有找到我的答案。

I'm learning C, but have not had to use a long intbefore, so I'm not sure what I should be using.

我正在学习 C,但之前没有使用过 a long int,所以我不确定我应该使用什么。

What is the specifier I am chasing?

我要追求的说明符是什么?

回答by eq-

I recommend using standard order (i.e. unsigned long int). %luis the format tag you're looking for.

我建议使用标准顺序(即 unsigned long int)。%lu是您要查找的格式标签。

printf("%lu", 5ul);

回答by Kiril Kirov

int unsigned long number = 600851475143LU;
printf( "%lu", number );

prints 600851475143

印刷 600851475143