代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
int main()
{
char h[17];
for (int i = 0; i < 17; i++)
cout << (int)h[i] << ", ";
cout << endl << endl;
unsigned long long a = 0x1234567890abcd;
sprintf(h, "%016I64x", a);
for (int i = 0; i < 17; i++)
cout << (int)h[i] << ", ";
}
结果:
-52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52,
48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 97, 98, 99, 100, 0
证明:
sprintf 中 "%016I64x" 将最后的 '\0' ,复制给了 h,所以 h 需要 17 字节
网友评论