Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you format an unsigned long long int using printf?

#include <stdio.h> int main() {     unsigned long long int num = 285212672; //FYI: fits in 29 bits     int normalInt = 5;     printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);     return 0; } 

Output:

My number is 8 bytes wide and its value is 285212672l. A normal number is 0. 

I assume this unexpected result is from printing the unsigned long long int. How do you printf() an unsigned long long int?

like image 831
andrewrk Avatar asked Aug 05 '08 20:08

andrewrk


People also ask

How do you display unsigned long long int?

Use the format specifier “ %lu” . This format specifier is used to output an Unsigned long int.


1 Answers

Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).

printf("%llu", 285212672); 
like image 110
John Downey Avatar answered Oct 07 '22 13:10

John Downey