如何在gcc中打印UINT64_t?

Ram*_*ant 2 c unix function

为什么这段代码不起作用?

#include <stdio.h>
main()
{
    UINT64_t ram = 90;
    printf("%d""\n", ram);
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

In function \u2018main\u2019
error: \u2018UINT64_t\u2019 undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: expected \u2018;\u2019 before \u2018ram\u2019
Run Code Online (Sandbox Code Playgroud)

niy*_*asc 8

uint64_t在标准整数类型头文件中定义.即,stdint.h.所以首先要包含stdint.h在你的程序中.

然后你可以使用格式说明符"%"PRIu64来打印你的值:即

printf("%" PRIu64 "\n", ram);
Run Code Online (Sandbox Code Playgroud)

您也可以参考这个问题如何在C中打印int64_t类型

  • 虽然`uint64_t`在`<stdint.h>`中定义,但是诸如`PRIu64`之类的宏在`<inttypes.h>`中定义.不同寻常的是,`<inttypes.h>`实际上包括`<stdint.h>`; 没有其他标准C头包含另一个. (3认同)