如何打印“unsigned long”在C语言中?

发布于 2024-09-08 17:51:48 字数 555 浏览 12 评论 0原文

我永远无法理解如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

好菇凉咱不稀罕他 2024-09-15 17:51:48

%luunsigned long 的正确格式。听起来这里还有其他问题,例如内存损坏或未初始化的变量。也许向我们展示更大的图景?

%lu is the correct format for unsigned long. Sounds like there are other issues at play here, such as memory corruption or an uninitialized variable. Perhaps show us a larger picture?

无人接听 2024-09-15 17:51:48

对于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

空心↖ 2024-09-15 17:51:48
  • %lu 表示unsigned long
  • %llu 表示unsigned long long
  • %lu for unsigned long
  • %llu for unsigned long long
策马西风 2024-09-15 17:51:48

在您尝试的所有组合中, %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 the l).

祁梦 2024-09-15 17:51:48

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.

始终不够爱げ你 2024-09-15 17:51:48

格式为%lu

请在 此处

The format is %lu.

Please check about the various other datatypes and their usage in printf here

和我恋爱吧 2024-09-15 17:51:48
int main()
{
    unsigned long long d;
    scanf("%llu",&d);
    printf("%llu",d);
    getch();
}

这会有帮助的。 。 。

int main()
{
    unsigned long long d;
    scanf("%llu",&d);
    printf("%llu",d);
    getch();
}

This will be helpful . . .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文