Put an l (lowercased letter L) directly before the specifier.

unsigned long n;
long m;

printf("%lu %ld", n, m);
Answer from postfuturist on Stack Overflow
🌐
U-Boot Documentation
docs.u-boot.org › en › v2024.10 › develop › printf.html
Printf() format codes — Das U-Boot unknown version documentation
Printf() format codes · View page source · Each conversion specification consists of: leading ‘%’ character · zero or more flags · an optional minimum field width · an optional precision field preceded by ‘.’ · an optional length modifier · a conversion specifier ·
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › format-specification-syntax-printf-and-wprintf-functions
Format Specification Syntax: `printf` and `wprintf` Functions | Microsoft Learn
Character and string arguments that are specified by using C and S are interpreted as wchar_t and wchar_t* by printf family functions, or as char and char* by wprintf family functions. This behavior is Microsoft-specific. For historical reasons, the wprintf functions use c and s to refer to wchar_t characters, and C and S specify narrow characters. Integer types such as short, int, long, long long, and their unsigned variants, are specified by using d, i, o, u, x, and X.
🌐
w3resource
w3resource.com › c-programming-exercises › c-snippets › conversion-specifier-for-formatting-long-with-printf-in-c.php
Conversion Specifier for Printing long in C with printf
For printing a long integer, you use the %ld specifier. This specifier tells printf to format the corresponding argument as a long int.
🌐
Cplusplus
cplusplus.com › reference › cstdio › printf
Printf
printf · function · <cstdio> int printf ( const char * format, ... ); Print formatted data to stdout · Writes the C string pointed by format to the standard output (stdout).
🌐
NXP
community.nxp.com › t5 › MCUXpresso-General › printf-double-and-unsigned-long-int-support › td-p › 967954
printf(), double and unsigned long int support - NXP Community
June 28, 2019 - where i is declared as uint64_t cast as an unsigned long int equal to 0x100000001 displays as "i = lu". If instead I select Newlib (nohost) in the Library/Header category, the second printf() call shown above will render the expected value, however when the first printf() shown is encountered the hard fault handler is inevitably invoked.
Find elsewhere
🌐
cppreference.com
en.cppreference.com › cpp › io › c › fprintf
std::printf, std::fprintf, std::sprintf, std::snprintf - cppreference.com
#include <cinttypes> #include <cstdint> #include <cstdio> #include <limits> int main() { const char* s = "Hello"; std::printf("Strings:\n"); // same as std::puts("Strings:"); std::printf("\t[s]\n", s); std::printf("\t[%-10s]\n", s); std::printf("\t[%*s]\n", 10, s); std::printf("\t[%-10.*s]\n", 4, s); std::printf("\t[%-*.*s]\n", 10, 4, s); std::printf("Characters:\t%c %%\n", 'A'); std::printf("Integers:\n"); std::printf("\tDecimal: \t%i %d %.6i %i %.0i %+i %i\n", 1, 2, 3, 0, 0, 4,-4); std::printf("\tHexadecimal:\t%x %x %X %#x\n", 5,10,10, 6); std::printf("\tOctal: \t%o %#o %#o\n", 10, 10, 4);
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Printing long value with sprintf - Programming - Arduino Forum
June 2, 2016 - I have been fighting with this for a long time. The code snipped below is to illustrate my problem. I have a assigned a long value. This is a 4 byte signed value. I assign it a number that is larger then would fit in a 2 byte integer. When I just print the value direct it is correctly displayed.
🌐
University of Surrey
personalpages.surrey.ac.uk › r.bowden › C › printf.html
Format Codes for printf
June 9, 2023 - int printf(const char *format, ...) int fprintf(FILE *stream, const char *format, ...) int sprintf(char *string, const char *format, ...) The functions return the number of characters written, or a negative value if an error occurred. The format string is of the form ·
🌐
Wyzant
wyzant.com › resources › ask an expert
How do you format an unsigned long long int using printf? | Wyzant Ask An Expert
May 3, 2019 - #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.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-format-a-Java-int-with-printf-example
How to format a Java int or long with printf example
There are two key takeaways from this Java int printf example: The %d specifier works for long, int, double and short datatypes.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › cpp-printf-function
C++ printf() Function - GeeksforGeeks
July 23, 2025 - // C++ Program to demonstrate // use of printf() #include <iostream> using namespace std; int main() { char a[] = "geeksforgeeks"; printf("The total no of characters returned by " "printf() is %d", printf("%s", a)); return 0; }
🌐
Thinkage
thinkage.ca › gcos › expl › b › lib › printf.html
PRINTF - formatted print.
printf( "%?.?f", 5, 3, num ); You may also use '?' to specify that the fill character P is to be obtained from the argument list. If you need a fill character '?', you must supply an argument of '?' in the argument list. Except where noted above, supplied field widths are minimum values and the field will be longer if the argument does not fit.
🌐
Ulisboa
disciplinas.tecnico.ulisboa.pt › SIRS › 2015-2016 › labs › 1 › printf_Format_Strings.pdf pdf
Printf Format Strings
long double. The length is wrong, and the results are ugly! The length modifier is all about helping printf deal with cases where you're using unusually big (or unusually small)
🌐
Lsu
ld2010.scusa.lsu.edu › cppreference › wiki › c › io › printf
c:io:printf
The return value of printf is the number of characters printed, or a negative number if an error occurred. There are different %-codes for different variable types, as well as options to limit the length of the variables and whatnot. An integer placed between a % sign and the format command acts as a minimum field width specifier, and pads the output with spaces or zeros to make it long enough.
🌐
Linux Man Pages
man7.org › linux › man-pages › man3 › printf.3.html
printf(3) - Linux manual page
One can also specify explicitly which argument is taken, at each place where an argument is required, by writing "%m$" instead of '%' and "*m$" instead of '*', where the decimal integer m denotes the position in the argument list of the desired argument, indexed starting from 1. Thus, printf("%*d", width, num); and printf("%2$*1$d", width, num); are equivalent.
🌐
Quora
quora.com › How-can-I-print-an-unsigned-long-int-in-C-language
How to print an unsigned long int in C language - Quora
Answer (1 of 6): %lu is the standard order for unsigned long int. Just ran this snippet and it works for me. #include int main(void) { int unsigned long number = 600851475143LU; printf( "%lu", number ); return 0; } Let me know if you face some issue with this Vineeta Karki.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-long
C Long - GeeksforGeeks
June 15, 2026 - #include <stdio.h> int main() { ... 9223372036854775807 Size of long long: 8 bytes · We can use a long modifier with double datatype to create a long double variable....
🌐
Post.Byes
post.bytes.com › home › forum › topic
How to output long long or int64? - Post.Byes
Then you can do something like: #include "pstdint.h" ... int64_t v = INT64_C (9999999999999) ; printf ("%" PRINTF_INT64_MO DIFIER "d\n", v); The point being that some compilers use "%lld", and others use "%I64d", and pstdint.h tries to give you the right one. -- Paul Hsieh ... Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform. ... Re: How to output long long or int64?