简体   繁体   中英

How to print UINT64_t in gcc?

Why this code is not working?

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

I got the Following errors:

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

uint64_t is defined in Standard Integer Type header file. ie, stdint.h . So first include stdint.h in your program.

Then you can use format specifier "%"PRIu64 to print your value: ie

printf("%" PRIu64 "\n", ram);

You can refer this question also How to print a int64_t type in C

Full working example: http://ideone.com/ttjEOB

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int main()
{
    uint64_t ram = 90;
    printf("%" PRIu64 "\n", ram);
}

You forgot some headers, wrote incorrectly uint64_t and can't use %d with uint64_t

Add:

#include <inttypes.h>

And use PRIu64 (outside of quotation marks like so):

printf("%"PRIu64"\n", ram);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM