Thread: Apart from size difference between long int, short int & int what else is there?

  1. #1
    Registered User
    Join Date
    Jun 2015
    Location
    Delhi
    Posts
    35

    Apart from size difference between long int, short int & int what else is there?

    I understand that the sizeof(short_int)=2 bytes, sizeof(int)=4 bytes, sizeof(long_int)=8 bytes but what I mean to ask is if it is the case that int can store a digit up to 10^M, short int up to 10^L & long int up to 10^N where L<M<N? Is it the case?

    If my understanding is correct then how can I know about these limits of storage i.e. L,M,N? If not then what is the real thing?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    The sizes of the integral types have implementation defined minimums and maximums which are defined in the <limits.h> include file.

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    In the case of Microsoft compilers, int and long int are both 4 bytes (32 bits) and long long int is 8 bytes (64 bits).

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by smrtshrm
    I understand that the sizeof(short_int)=2 bytes, sizeof(int)=4 bytes, sizeof(long_int)=8 bytes
    Note that this is not necessarily true. The relevant rule is that sizeof(char) == 1, sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long), where I use <= with pseudo-mathematical syntax. Related to this is the rule that CHAR_BIT is at least 8. Of course, the minimum guaranteed ranges as mentioned by jimblumberg must still hold for the implementation to conform to the standard.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Largest/Smallest Int, Short, Long using pow?
    By jdowning in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2013, 11:18 AM
  2. How come short + int = int but short + uint = long?
    By y99q in forum C# Programming
    Replies: 2
    Last Post: 10-29-2011, 11:16 AM
  3. Short/long/signed/unsigned int
    By scuzzo84 in forum C Programming
    Replies: 4
    Last Post: 09-13-2005, 11:40 PM
  4. short and long int
    By gogo in forum C Programming
    Replies: 3
    Last Post: 03-10-2003, 06:25 AM
  5. bytes long and short
    By SAMSAM in forum Game Programming
    Replies: 0
    Last Post: 03-08-2003, 09:50 AM