INT versus LONG

INT versus LONG

What are the advantages of using one over the other?
Last edited on
My girlfriend prefers long...

Seriously though...

She does.

But seriously though...

Use int generally. Use long long when you need the extra storage space. long long will of course be a little slower for doing things with.
The chart here says they are the same though?

http://www.cplusplus.com/doc/tutorial/variables/

int >> Integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295

long int (long) >> Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
That's why I said long long. ;)

If you actually want int vs long answered... I have no idea why that type exists and have never used it. Sorry.
Last edited on
ahh, i didn't realize you could make types like that.

I'm still a beginner lol.


So i could do "long char" or "long float"?

What does the long do. Double the size?
Last edited on
Historically many computers used 8-bit processors (CPU), then later 16-bit CPUs. On a 16-bit computer, an int would be a 16-bit value. When something more precise was required, type long could be used, which was a 32-bit value.

But nowadays most computers use a 32-bit or even 64-bit CPU, and the size of an int has changed, along with that. The actual sizes of the each type will depend on several things, the hardware itself, and the operating system, and the particular compiler. Thus it isn't safe to assume anything, except that a type long on a given compiler will be at least as large as a type int.
So i could do "long char" or "long float"?

Not exactly. The larger type of char is wchar_t
And a double is in effect a "long float". It's best to think of float as analogous to a 16-bit int, and a double as being similar to an int
There is also a long double which is a bit more precise than a plain double, but it certainly isn't twice as long (usually).
Thanks for the description. That helped me understand it more.

I'll try to avoid long unless I absolutely need it for now.
Topic archived. No new replies allowed.