long int vs int

C, C++, Visual C++, C++.Net Topics
Post Reply
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

long int vs int

Post by SukhdeepMankoo » Tue Apr 16, 2013 11:15 am

hi,
I searched lot of times in Google, not able to find significant difference between long int and int. As both has same size. How can I know at what time which should I use.

[ Post made via Mobile Device ] Image
User avatar
Herath
Major
Major
Posts: 417
Joined: Thu Aug 05, 2010 7:09 pm

Re: long int vs int

Post by Herath » Tue Apr 16, 2013 4:26 pm

According to this "int" type should have at least 16bit width while "long" type-modified fundamental type has a minimum of 32bit width. Since most of the todays systems are 32bit systems, int and long int should mean the same. The type modifier "long" might not have an effect against the already-32bit "int" type.
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

Re: long int vs int

Post by SukhdeepMankoo » Tue Apr 16, 2013 4:40 pm

why they declare long int. if they are same.

[ Post made via Mobile Device ] Image
User avatar
Herath
Major
Major
Posts: 417
Joined: Thu Aug 05, 2010 7:09 pm

Re: long int vs int

Post by Herath » Tue Apr 16, 2013 5:05 pm

Suppose that your program is being compiled with a compiler that compiles the int as a 16bit wide data type. If you still need a 32bit wide data type for storing some large value, it is required to use the long type modifier before int inorder to make it 32bit wide when compiling with a 16bit compiler. And that is what I have in my mind. :) .


What i have meant by a 16bit compiler is a compiler that compiles the source code for a 16bit processor.
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

Re: long int vs int

Post by SukhdeepMankoo » Wed Apr 17, 2013 6:44 am

thanks,
what about long long int and long int

[ Post made via Mobile Device ] Image
User avatar
Herath
Major
Major
Posts: 417
Joined: Thu Aug 05, 2010 7:09 pm

Re: long int vs int

Post by Herath » Wed Apr 17, 2013 8:34 am

long - target type will have width of at least 32 bits.
long long - target type will have width of at least 64 bits (since C++11)

Copied from : http://en.cppreference.com/w/cpp/language/types
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

Re: long int vs int

Post by SukhdeepMankoo » Fri Apr 19, 2013 10:06 am

Thanks

[ Post made via Mobile Device ] Image
evangilbort
Sergeant
Sergeant
Posts: 12
Joined: Fri Jun 21, 2013 12:19 pm

Re: long int vs int

Post by evangilbort » Mon Jun 24, 2013 4:51 pm

Int is the default type integer that supported by your compiler and it's typically compatible with your hardware and operating system. Integer data types may be different size and it not be allowed to contain negative values. It is commonly represented in a computer as a binary groups of digits.
Post Reply

Return to “C/C++ Programming”