<p>The <code>printf</code> function takes an argument type, such as <code>%d</code> or <code>%i</code> for a <code>signed int</code>. However, I don't see anything for a <code>long</code> value.</p>

[{'answer_id': 38566, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 4, 'selected': False, 'text': '<p><code>%ld</code> see <a href="http://www.cplusplus.com/reference/clibrary/cstdio/printf.html" rel="noreferrer"><code>printf</code> reference on cplusplus.com</a></p>\n'}, {'answer_id': 38570, 'author': 'postfuturist', 'author_id': 1892, 'author_profile': 'https://Stackoverflow.com/users/1892', 'pm_score': 11, 'selected': True, 'text': '<p>Put an <code>l</code> (lowercased letter L) directly before the specifier.  </p>\n\n<pre><code>unsigned long n;\nlong m;\n\nprintf("%lu %ld", n, m);\n</code></pre>\n'}, {'answer_id': 38607, 'author': 'Blorgbeard', 'author_id': 369, 'author_profile': 'https://Stackoverflow.com/users/369', 'pm_score': 8, 'selected': False, 'text': '<p>I think you mean:</p>\n\n<pre><code>unsigned long n;\nprintf("%lu", n);   // unsigned long\n</code></pre>\n\n<p>or</p>\n\n<pre><code>long n;\nprintf("%ld", n);   // signed long\n</code></pre>\n'}, {'answer_id': 40354, 'author': "Andrew O'Reilly", 'author_id': 3692, 'author_profile': 'https://Stackoverflow.com/users/3692', 'pm_score': -1, 'selected': False, 'text': '<p>I think to answer this question definitively would require knowing the compiler name and version that you are using and the platform (CPU type, OS etc.) that it is compiling for.</p>\n'}, {'answer_id': 13112207, 'author': 'Dolan Antenucci', 'author_id': 318870, 'author_profile': 'https://Stackoverflow.com/users/318870', 'pm_score': 4, 'selected': False, 'text': '<p>In case you\'re looking to print <code>unsigned long long</code> as I was, use:</p>\n\n<pre><code>unsigned long long n;\nprintf("%llu", n);\n</code></pre>\n\n<p>For all other combinations, I believe you use the table from <a href="http://www.cplusplus.com/reference/clibrary/cstdio/printf/" rel="noreferrer">the printf manual</a>, taking the row, then column label for whatever type you\'re trying to print (as I do with <code>printf("%llu", n)</code> above).</p>\n'}, {'answer_id': 14610883, 'author': 'Dave Dopson', 'author_id': 407731, 'author_profile': 'https://Stackoverflow.com/users/407731', 'pm_score': 7, 'selected': False, 'text': '<p>On most platforms, <code>long</code> and <code>int</code> are the same size (32 bits). Still, it does have its own format specifier:</p>\n\n<pre><code>long n;\nunsigned long un;\nprintf("%ld", n); // signed\nprintf("%lu", un); // unsigned\n</code></pre>\n\n<p>For 64 bits, you\'d want a <code>long long</code>:</p>\n\n<pre><code>long long n;\nunsigned long long un;\nprintf("%lld", n); // signed\nprintf("%llu", un); // unsigned\n</code></pre>\n\n<p>Oh, and of course, it\'s different in Windows:</p>\n\n<pre><code>printf("%l64d", n); // signed\nprintf("%l64u", un); // unsigned\n</code></pre>\n\n<p>Frequently, when I\'m printing 64-bit values, I find it helpful to print them in hex (usually with numbers that big, they are pointers or bit fields).</p>\n\n<pre><code>unsigned long long n;\nprintf("0x%016llX", n); // "0x" followed by "0-padded", "16 char wide", "long long", "HEX with 0-9A-F"\n</code></pre>\n\n<p>will print:</p>\n\n<pre><code>0x00000000DEADBEEF\n</code></pre>\n\n<p>Btw, "long" doesn\'t mean that much anymore (on mainstream x64).  "int" is the platform default int size, typically 32 bits.  "long" is usually the same size.  However, they have different portability semantics on older platforms (and modern embedded platforms!).  "long long" is a 64-bit number and usually what people meant to use unless they really really knew what they were doing editing a piece of x-platform portable code.  Even then, they probably would have used a macro instead to capture the semantic meaning of the type (eg uint64_t).</p>\n\n<pre><code>char c;       // 8 bits\nshort s;      // 16 bits\nint i;        // 32 bits (on modern platforms)\nlong l;       // 32 bits\nlong long ll; // 64 bits \n</code></pre>\n\n<p>Back in the day, "int" was 16 bits.  You\'d think it would now be 64 bits, but no, that would have caused insane portability issues.  Of course, even this is a simplification of the arcane and history-rich truth.  See <a href="http://en.wikipedia.org/wiki/Integer_(computer_science)" rel="noreferrer">wiki:Integer</a></p>\n'}, {'answer_id': 15237828, 'author': 'krato', 'author_id': 2130213, 'author_profile': 'https://Stackoverflow.com/users/2130213', 'pm_score': 4, 'selected': False, 'text': '<p>It depends, if you are referring to unsigned long the formatting character is <code>"%lu"</code>.  If you\'re referring to signed long the formatting character is <code>"%ld"</code>.</p>\n'}]
['https://Stackoverflow.com/questions/38561', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/572/']