Home c How to print unsigned numbers in printf?

How to print unsigned numbers in printf?




There is a code:

unsigned long x = 0;
printf ("x =% d \ n");

The compiler shows a warning:

example.cc:139:35: warning: format "% d" expects argument of type "int", but argument 2 has type "long unsigned int" [-Wformat]

Answer 1, authority 100%

You need the % lu specifier.

printf – C++ Reference

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions