Ramakant
Ramakant

Reputation: 195

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

Upvotes: 8

Views: 46315

Answers (3)

niyasc
niyasc

Reputation: 4490

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: i.e.

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

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

Upvotes: 14

ckolivas
ckolivas

Reputation: 128

Add:

#include <inttypes.h>

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

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

Upvotes: 2

xanatos
xanatos

Reputation: 111930

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

Upvotes: 5

Related Questions