printf如何输出64位整数
From: http://blog.csdn.net/zzqhost/article/details/6064886
关于printf函数输出64位数的问题,其实在window下和linux下是不一样的:
linux下是
printf("%lld/n",a);
printf("%llu/n",a);
windows下是
printf("%I64d/n",a);
printf("%I64u/n",a);
完整程序如下:
- [zcm@c #51]$cat a.c
- // linux平台C程序
- #include <stdio.h>
- typedef unsigned long long int64;
- typedef unsigned long long uint64;
- int main ( void )
- {
- int64 c = 0x123456789LL; // 有符号
- uint64 uc = 0x123456789ULL; // 无符号
- printf("%lld, %llu\n", c, uc); // 整数形式输出
- printf("%llx, %llx\n", c, uc); // 十六进制格式输出
- printf("%#llx, %#llx\n", c, uc);// 带0x的十六进制格式输出
- return 0;
- }
- [zcm@c #53]$make
- gcc -g -O2 -o a a.c
- [zcm@c #54]$./a
- 4886718345, 4886718345
- 123456789, 123456789
- 0x123456789, 0x123456789
- [zcm@c #55]$
[zcm@c #51]$cat a.c // linux平台C程序 #include <stdio.h> typedef unsigned long long int64; typedef unsigned long long uint64; int main ( void ) { int64 c = 0x123456789LL; // 有符号 uint64 uc = 0x123456789ULL; // 无符号 printf("%lld, %llu\n", c, uc); // 整数形式输出 printf("%llx, %llx\n", c, uc); // 十六进制格式输出 printf("%#llx, %#llx\n", c, uc);// 带0x的十六进制格式输出 return 0; } [zcm@c #53]$make gcc -g -O2 -o a a.c [zcm@c #54]$./a 4886718345, 4886718345 123456789, 123456789 0x123456789, 0x123456789 [zcm@c #55]$jpg改rar
![](https://images2017.cnblogs.com/blog/923483/201709/923483-20170925095829307-359366136.jpg)