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
🌐
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.
Discussions

Printf long long int in C with GCC? - Stack Overflow
How do I printf long long int and also unsigned long long int in C99 using GCC? I have searched the other posts which suggest to use %lld but it gives these warnings: warning#1: unknown convers... More on stackoverflow.com
🌐 stackoverflow.com
c - How to printf long long - Stack Overflow
I'm doing a program that aproximate PI and i'm trying to use long long, but it isn't working. Here is the code #include #include typedef long long num; main(){ num... More on stackoverflow.com
🌐 stackoverflow.com
Printing long value with sprintf
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. More on forum.arduino.cc
🌐 forum.arduino.cc
5
0
June 2, 2016
How to print a 64 bit long in 32 bit mode using printf?
If you're not already, use the types in for specific widths, instead of assuming that int, long, long long, etc. have a given size. int32_t, int64_t or whatever. If you also #include you can use those types with printf like so: int32_t foo = 1; int64_t bar = 2; printf("foo is %" PRId32 "\nbar is %" PRId64 "\n", foo, bar); More on reddit.com
🌐 r/C_Programming
4
8
April 30, 2015
🌐
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.
🌐
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 ·
🌐
IncludeHelp
includehelp.com › c › arguments-for-printf-that-formats-a-long-datatype.aspx
Arguments for printf() that formats a long datatype
July 10, 2022 - C language code for understanding ... //declaring an unsigned long long int variable long double ld; //declaring a long double variable printf("Enter long int: "); scanf("%ld", &li); //argument in printf for long int(%ld) printf("Enter unsigned Long Int: "); scanf("%lu", &uli); ...
🌐
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.
Find elsewhere
🌐
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.
🌐
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.
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 60111-displaying-long-long-printf.html
Displaying a 'long long' with printf
December 27, 2004 - ... I decided to post my original response - although it's not the root cause of trinitrotoluene's problems, it is a problem that's popped up here a few times in the past. In short, you can use the MS C-runtime library (MSVCRT.DLL) with MinGW - and the version of printf() in this library uses "%I64" instead of "%ll" when specifying a 64bit integer.
🌐
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....
🌐
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).
🌐
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.
🌐
Unstop
unstop.com › home › blog › format specifiers in c — complete list with code examples (2026)
Format Specifiers in C — Complete List with Code Examples (2026)
May 19, 2026 - The %lu format specifier is used to print unsigned long integers in C. An unsigned long integer is a non-negative integer that typically occupies more memory than a standard unsigned int, allowing it to represent a larger range of values.
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_format_specifiers.htm
Format Specifiers in C
C uses %d for signed integer, %i for unsigned integer, %ld or %li for long integer, %o or %O for octal representation, and %x or %X for hexadecimal representation of an integer. The following example highlights how integer format specifiers ...
🌐
University of Surrey
personalpages.surrey.ac.uk › r.bowden › C › printf.html
Format Conversions: printf, fprintf, sprintf
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 ·