Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printf format for unsigned __int64 on Windows

I need to print a ULONGLONG value (unsigned __int64). What format should i use in printf ? I found %llu in another question but they say it is for linux only.

Thanks for your help.

like image 819
Virus721 Avatar asked Aug 07 '13 15:08

Virus721


People also ask

What is %z in printf?

We should use “%zu” to print the variables of size_t length. We can use “%d” also to print size_t variables, it will not show any error. The correct way to print size_t variables is use of “%zu”. In “%zu” format, z is a length modifier and u stand for unsigned type.

What is the format specifier for uint64_t?

for uint64_t type: #include <inttypes. h> uint64_t t; printf("%" PRIu64 "\n", t); you can also use PRIx64 to print in hexadecimal.

How do I print long unsigned int?

To print an unsigned int number, use the %u notation. To print a long value, use the %ld format specifier. You can use the l prefix for x and o, too. So you would use %lx to print a long integer in hexadecimal format and %lo to print in octal format.

Can we use %d in printf?

In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.


2 Answers

Using Google to search for “Visual Studio printf unsigned __int64” produces this page as the first result, which says you can use the prefix I64, so the format specifier would be %I64u.

like image 100
Eric Postpischil Avatar answered Sep 21 '22 14:09

Eric Postpischil


%llu is the standard way to print unsigned long long, it's not just for Linux, it's actually in C99. So the problem is actually to use a C99-compatible compiler, i.e, not Visual Studio.

C99 7.19.6 Formatted input/output functions

ll(ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long long int or unsigned long long int argument; or that a following n conversion specifier applies to a pointer to along long int argument.

like image 30
Yu Hao Avatar answered Sep 20 '22 14:09

Yu Hao