如何打印“unsigned long”在C语言中?
我永远无法理解如何在 C 中打印 unsigned long
数据类型。
假设 unsigned_foo
是一个 unsigned long
,然后我尝试:
printf( "%lu\n", unsigned_foo)
printf("%du\n", unsigned_foo)
printf("%ud\n", unsigned_foo)
- <代码>printf("%ll\n", unsigned_foo)
printf("%ld\n", unsigned_foo)
printf("%dl\n", unsigned_foo)< /code>
并且它们都打印某种 -123123123
数字,而不是我拥有的 unsigned long
。
I can never understand how to print unsigned long
datatype in C.
Suppose unsigned_foo
is an unsigned long
, then I try:
printf("%lu\n", unsigned_foo)
printf("%du\n", unsigned_foo)
printf("%ud\n", unsigned_foo)
printf("%ll\n", unsigned_foo)
printf("%ld\n", unsigned_foo)
printf("%dl\n", unsigned_foo)
And all of them print some kind of -123123123
number instead of unsigned long
that I have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
%lu
是unsigned long
的正确格式。听起来这里还有其他问题,例如内存损坏或未初始化的变量。也许向我们展示更大的图景?%lu
is the correct format forunsigned long
. Sounds like there are other issues at play here, such as memory corruption or an uninitialized variable. Perhaps show us a larger picture?对于int
%d
对于long int
%ld
对于long long int
%lld
对于unsigned long long int
%llu
For int
%d
For long int
%ld
For long long int
%lld
For unsigned long long int
%llu
%lu
表示unsigned long%llu
表示unsigned long long%lu
for unsigned long%llu
for unsigned long long在您尝试的所有组合中,
%ld
和%lu
是唯一有效的 printf 格式说明符。%lu
(长无符号十进制)、%lx
或%lX
(带有小写或大写字母的长十六进制)和%lo
(长八进制)是 unsigned long 类型变量唯一有效的格式说明符(当然,您可以在%
和l 之间添加字段宽度、精度等修饰符)。
Out of all the combinations you tried,
%ld
and%lu
are the only ones which are valid printf format specifiers at all.%lu
(long unsigned decimal),%lx
or%lX
(long hex with lowercase or uppercase letters), and%lo
(long octal) are the only valid format specifiers for a variable of type unsigned long (of course you can add field width, precision, etc modifiers between the%
and thel
).unsigned long 的正确说明符是
%lu
。如果您没有获得预期的确切值,那么您的代码中可能存在一些问题。
请在此处复制您的代码。然后也许有人可以更好地告诉你问题是什么。
The correct specifier for unsigned long is
%lu
.If you are not getting the exact value you are expecting then there may be some problems in your code.
Please copy your code here. Then maybe someone can tell you better what the problem is.
格式为
%lu
。请在 此处
The format is
%lu
.Please check about the various other datatypes and their usage in printf here
这会有帮助的。 。 。
This will be helpful . . .