You must use %ld to print a long int, and %lld to print a long long int.

Note that only long long int is guaranteed to be large enough to store the result of that calculation (or, indeed, the input values you're using).

You will also need to ensure that you use your compiler in a C99-compatible mode (for example, using the -std=gnu99 option to gcc). This is because the long long int type was not introduced until C99; and although many compilers implement long long int in C90 mode as an extension, the constant 2147483648 may have a type of unsigned int or unsigned long in C90. If this is the case in your implementation, then the value of -2147483648 will also have unsigned type and will therefore be positive, and the overall result will be not what you expect.

Answer from caf on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ c-long
C Long - GeeksforGeeks
June 15, 2026 - The long int literals can be represented by a numeric value followed by "LL" or "ll" as the suffix. ... Example: This example demonstrates how to declare long long variables and check their memory footprint using sizeof.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_data_types_extended.php
C More Data Types (Extended Types)
printf("Size of int: %zu bytes\n", sizeof(int)); printf("Size of double: %zu bytes\n", sizeof(double)); printf("Size of short int: %zu bytes\n", sizeof(short int)); printf("Size of unsigned int: %zu bytes\n", sizeof(unsigned int)); printf("Size of long int: %zu bytes\n", sizeof(long int)); printf("Size of long long int: %zu bytes\n", sizeof(long long int)); printf("Size of unsigned long long int: %zu bytes\n", sizeof(unsigned long long int)); printf("Size of long double: %zu bytes\n", sizeof(long double)); ... Tip: When you really need exact control over the size of your numbers, you can use the fixed-width types, which you will learn about later. Note: This page is just to show you that C has other extended types, but for now we will keep focusing on the basic types (int, float, double, char) in this tutorial.
Discussions

Printing long int value in C - Stack Overflow
I have two variables of long int type as shown below: long int a=-2147483648, b=-2147483648; a=a+b; printf("%d",a); I am getting zero. I tried changing the type to long long int, but I'm still not More on stackoverflow.com
๐ŸŒ stackoverflow.com
Difference between Short, long and Long long int in C programming? - Stack Overflow
I am learning C programming online on my own so that I can be prepared for College in Winter 2016. I am learning about data types right now. I don't understand the difference between: short long ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Long Vs. Int C/C++ - What's The Point? - Stack Overflow
As I've learned recently, a long in C/C++ is the same length as an int. To put it simply, why? It seems almost pointless to even include the datatype in the language. Does it have any uses speci... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Data type `long` in C programming - Stack Overflow
With the L suffix, it's of type long int or long long int; again, the value is always correct -- and it happens that 131071100L is always of type long int. It's perfectly valid to initialize an object of some arithmetic type with an expression of a different numeric type. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ difference-between-long-int-and-long-long-int-in-c-cpp
Difference between long int and long long int in C/C++ - GeeksforGeeks
July 23, 2025 - Integers typically require 4 bytes of memory space and range from -2147483648 to 2147483647. Datatype Modifiers: As the name implies, datatype modifiers are used with the built-in data types to modify the length of data that a particular data ...
๐ŸŒ
CS UIC
cs.uic.edu โ€บ ~jbell โ€บ CourseNotes โ€บ C_Programming โ€บ DataTypes.html
C Programming Course Notes - Data Types
The int data type is always the "best" size for the particular computer it is running on, typically 32 bits ยท Format specifiers for ints are either %d or %i, for either printf or scanf. A long int typically uses twice as many bits as a regular int, allowing it to hold much larger numbers.
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ all about c language โ€บ long data type in c
Long Data Type in C | PrepInsta
January 19, 2023 - On this page we will discuss about Long Data Type which is used in C. The Long data type is a data type that represents a signed integer that is typically at least 32 bits long.
Top answer
1 of 2
13

C was originally written for 16-bit machines, where the fastest and most-convenient size of integer to work with were 16 bits. This was the original int type. Sometimes, programmers needed 32-bit numbers, so those were the long int type.

In due course, people ported C to 32-bit machines where the most convenient word size was 32 bits. They wanted to keep using int to mean the native word size, because for example about every C program in the real world has int i; in it somewhere, but sometimes, they also needed to use 16-bit numbers to save space. So those became the short int type.

Time passed, and C needed to be ported to 64-bit machines. By then, there were a lot of programs in existence that assumed long was exactly 32 bits wide, and unfortunately, a lot of programs that also assumed that a long was the same size as a pointer, an IPv4 address, a file offset, a timestamp, etc. Good code uses types such as size_t, uintptr_t, and off_t instead, but old versions of the system libraries defined their library functions to use long, so a lot of legacy code had to as well. Since C99 came out, there have also been types such as int32_t in the standard library to specify exact widths, and Unix and Windows have had them under different names for a while.

As a consequence of the types being used to mean contradictory things, compilers today give programmers the choice between long being 32 and 64 bits wide, and 64-bit compilers let int be either 32 or 64 bits wide, too. At least one real compiler defined int as 64 bits (the native word length) but long as 32 bits (so the system libraries and code would still work). The standards committee prohibited that in C11: long long int is now guaranteed to be at least as wide as long int, and long int at least as wide as int.

Because a lot of programs couldn't redefine long as 64 bits without breaking, C needed a new type that meant (at least) 64-bit. By then, the standards committee was reluctant to introduce new keywords outside a header file, so they reused an existing one instead and named it long long int.

In brief, you shouldnโ€™t make assumptions about what int and long mean beyond that int is at least 16 bits wide and fast, long is at least 32 bits wide, and on a C11 compiler long is at least as wide as int but no wider than long long. For general purposes, use int. If you need an array index, use size_t or ptrdiff_t. If you want to be sure you can hold a number over 32,767, and seriously expect you might need to run on some 16-bit machine someday, use long or the fast type from <inttypes.h>. If youโ€™re making a system call, use the same type as its arguments. If youโ€™re storing a pointer in an integer type, use uintptr_t. If you need a number at least 64 bits wide, use long long, and if you know exactly the width you need, use the exact-width type.

2 of 2
2

They are just different data types. They have different ranges. All store integers, but consume different memory and have different ranges. For eg: short int consumes 16bits, long int consumes 32bits and long long int consumes 64bits. The maximum value of short int is 32767. So of you need to store big values you need to use long int. Long long int is the biggest and it can store upto 20! More explanation and ranges are found here in the Wikipedia page All the best!

Find elsewhere
Top answer
1 of 5
90

When writing in C or C++, every datatype is architecture and compiler specific. On one system int is 32, but you can find ones where it is 16 or 64; it's not defined, so it's up to compiler.

As for long and int, it comes from times, where standard integer was 16bit, where long was 32 bit integer - and it indeed was longer than int.

2 of 5
74

The specific guarantees are as follows:

  • char is at least 8 bits (1 byte by definition, however many bits it is)
  • short is at least 16 bits
  • int is at least 16 bits
  • long is at least 32 bits
  • long long (in versions of the language that support it) is at least 64 bits
  • Each type in the above list is at least as wide as the previous type (but may well be the same).

Thus it makes sense to use long if you need a type that's at least 32 bits, int if you need a type that's reasonably fast and at least 16 bits.

Actually, at least in C, these lower bounds are expressed in terms of ranges, not sizes. For example, the language requires that INT_MIN <= -32767, and INT_MAX >= +32767. The 16-bit requirements follows from this and from the requirement that integers are represented in binary.

C99 adds <stdint.h> and <inttypes.h>, which define types such as uint32_t, int_least32_t, and int_fast16_t; these are typedefs, usually defined as aliases for the predefined types.

(There isn't necessarily a direct relationship between size and range. An implementation could make int 32 bits, but with a range of only, say, -2**23 .. +2^23-1, with the other 8 bits (called padding bits) not contributing to the value. It's theoretically possible (but practically highly unlikely) that int could be larger than long, as long as long has at least as wide a range as int. In practice, few modern systems use padding bits, or even representations other than 2's-complement, but the standard still permits such oddities. You're more likely to encounter exotic features in embedded systems.)

๐ŸŒ
Quora
quora.com โ€บ What-do-you-mean-by-a-long-long-int-in-C-programming
What do you mean by a long long int in C programming? - Quora
Answer (1 of 7): A long long is requires twice as much memory as a long. The actual memory required is compiler and architecture dependent. In my experience using Linux, a long is 64 bits (8 bytes) and a long long needs 128 bits (16 bytes). The long long is normally used when dealing with very la...
๐ŸŒ
YouTube
youtube.com โ€บ sonar systems
short, long & long long Variables (Integers) - C Programming - YouTube
โญ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give...
Published: November 3, 2021
Views: 5K
Top answer
1 of 2
3

The type of an unsuffixed integer constant like 131071100 is the first of int, long int, and long long int in which its value can be represented. The value of 131071100 is always mathematically correct; only its type varies (and since long int is at least 32 bits, it's always either an int or a long int).

With the L suffix, it's of type long int or long long int; again, the value is always correct -- and it happens that 131071100L is always of type long int.

It's perfectly valid to initialize an object of some arithmetic type with an expression of a different numeric type. The value is implicitly converted to the target type. And in this case, since the target type is long int, there is no risk of overflow.

For your particular case, the only difference between

long int numberOfPoints = 131071100;

and

long int numberOfPoints = 131071100L;

is that the latter is slightly more explicit; the meaning is exactly the same.

The L suffix is still needed if the expression is more complicated than a single constant. For example, if you write:

long int foo = 1024 * 1024 * 1024;

then each constant 1024 is of type int -- and so is the entire expression. If int happens to be just 16 bits, then the multiplication will overflow, even though the mathematical result would fit in a long int. (The type of a literal is adjusted depending on its value; the type of a large expression is not.) To avoid that problem, you can write:

long int foo = 1024L * 1024L * 1024L;
2 of 2
1

(A previous answer here was incorrect and has been amended.)

Per the ANSI C specification (similar language exists in C99 and C++ specifications):

The type of an integer constant is the first of the corresponding list in which its value can be represented.

Unsuffixed decimal: int, long int, unsigned long int.

Unsuffixed octal or hexadecimal: int, unsigned int, long int, unsigned long int.

Suffixed by the letter u or U: unsigned int, unsigned long int.

Suffixed by the letter l or L: long int, unsigned long int.

Suffixed by both the letters u or U and l or L: unsigned long int.

Therefore, there will not be any difference between the two expressions, since C guarantees that the constant's type will be long enough to hold the value.

๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ C_data_types
C data types - Wikipedia
2 weeks ago - The C standard library contains ... size, independent of the language implementation on specific hardware platforms. The C language provides the four basic arithmetic type specifiers char, int, float and double (as well as the Boolean type bool), and the modifiers signed, unsigned, short, and long...
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ c-data-types
C Data Types
The size of int is 4 bytes. Here's a table containing commonly used types in C programming for quick access.
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ long and long long are both 8 bytes. what gives?
r/C_Programming on Reddit: long and long long are both 8 bytes. What gives?
May 22, 2016 -

Hi,

Dumb question -

I noticed that long int, and long long int are both 8 bytes each on my machine. Doesnt that imply that both have a similar range that they can store?

If yes, whats the point of long versus long long?

Top answer
1 of 5
17
https://en.wikipedia.org/wiki/C_data_types A long int is at least 4 bytes. A long long int is at least 8 bytes. Historically, you would only use a long long int if you really needed that data range, because it would most likely be slower on a 32 (or 16!) bit processor. Now that more processors (most likely including yours) are in fact 64 bits, the computer can deal with 64-bit integers just as easily (maybe more easily) than 32-bit, so the compiler may use a 64-bit integer anyway.
2 of 5
7
If yes, whats the point of long versus long long? The point is that not everybody is using the same platform you are. On a different platform, they might be different sizes. The standard doesn't say what size these types must be, it only gives a minimum. A long must be able to support at least 32 bits worth of data, so on your particular platform a long is longer than required, which is why there is no need for a long long on your platform. That isn't always the case. Edit: to elaborate a bit, the general practice on Unix systems is for long to be the native machine word width. So if you're compiling for 32 bit mode, long will be 4 bytes, and if you're compiling for 64 bit mode long will be 8 bytes. In both cases long long will be 8 bytes. (Again, this is just in the context of modern Unix systems, it does not apply to other platforms.) So if you want a value that tracks the machine word size across different architectures, use long, and if you want something that's 64 bits, use long long. On windows, long is always 32 bits even on 64 bit platforms, so you have to use something else (like size_t or ptrdiff_t) if you want an integer type that tracks the machine word size.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ [c/c++] how are long ints useful with modern computers?
[C/C++] How are long ints useful with modern computers? : r/learnprogramming
February 24, 2023 - However, many microprocessors still start from a 16b int and long int or long long int is a very useful thing. As others have noted, using uint32_t and others from stdint.h (or inttypes.h) is much better now-a-days. ... The advantage comes in that a larger group of bytes is moved into the CPU (registers) on one go, and then special instructions can be provided that will do all that shifting and looking up and such.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-int-and-long-in-C-programming-Is-there-any-use-of-the-long-type-in-computer-science-or-not
What is the difference between 'int' and 'long' in C programming? Is there any use of the long type in computer science or not? - Quora
Answer (1 of 3): There is a bit of history here. I started C programming at University in 1975 using UNIX Edition 5. The early versions of the programming language C only had the types of char, int and floating point. In the original C language specification, published in 1972, the float data ty...
๐ŸŒ
Quora
quora.com โ€บ What-is-data-type-long-in-C
What is data type long in C? - Quora
Answer (1 of 2): On a 64bit compiler โ€œlongโ€ is a 64bit 2s complement integer. On a 32bit compiler โ€œlongโ€ is a 32bit 2s complement integer. If you require a 64bit value, regardless of the compiler or processorโ€™s word size, you need to specify โ€œlong longโ€ which is always 64bit or, ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ int vs long in c++
r/learnprogramming on Reddit: int vs long in C++
August 14, 2023 -

On platforms like Gfg, leetcode etc., I have encountered function templates which use 'long' instead of 'int' as their return type/parameter type. My doubt is, when both 'int' and 'long' occupy exactly 4 bytes in memory and their ranges are exactly the same (-2^31 to 2^31 - 1), then what is the reason to use 'long' instead of int? If they want to make room to store larger values and are concerned about overflow, they should use 'long long' instead which occupies 8 bytes of memory.

Thanks in advance!