printf如何輸出64位整數(shù)
關(guān)于printf函數(shù)輸出64位數(shù)的問(wèn)題,其實(shí)在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平臺(tái)C程序 #include <stdio.h> typedef unsigned long long int64; typedef unsigned long long uint64; int main ( void ) { int64 c = 0x123456789LL; // 有符號(hào) uint64 uc = 0x123456789ULL; // 無(wú)符號(hào) printf("%lld, %llu\n", c, uc); // 整數(shù)形式輸出 printf("%llx, %llx\n", c, uc); // 十六進(jìn)制格式輸出 printf("%#llx, %#llx\n", c, uc);// 帶0x的十六進(jìn)制格式輸出 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平臺(tái)C程序 #include <stdio.h> typedef unsigned long long int64; typedef unsigned long long uint64; int main ( void ) { int64 c = 0x123456789LL; // 有符號(hào) uint64 uc = 0x123456789ULL; // 無(wú)符號(hào) printf("%lld, %llu\n", c, uc); // 整數(shù)形式輸出 printf("%llx, %llx\n", c, uc); // 十六進(jìn)制格式輸出 printf("%#llx, %#llx\n", c, uc);// 帶0x的十六進(jìn)制格式輸出 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
*博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。