Difference Between an Integer , short and long Variables

Int , short , long

Primary Data Types themselves could be of several types. For example, a char could be an unsigned char or a signed char. Or an int could be a short int or long int. Due these variations in the primitive data types, its very difficult to understand the concept. So let us take a closer look at these variations of primary data types in the tutorial:

=> Integers , long and short:
  • The range of an integer constant depends upon the compiler.
  • For a 16 bit Compiler like Turbo C or Turbo C++ the range is -32768 to 32767. 
  • For a 32 bit compiler like Visual Studio or gcc the range would be -2147483648 to 2147483647.
  • C offers a variation of the Integer data type i.e short and long integer values. 
  • The intention of providing these variations is to provide Integers with different ranges whenever possible. 
 


Each compiler can decide appropriate sizes of int , long and short depending on the operating system and hardware, for which it is being written, subject to following Rules:
  • shorts are atleast 2 bytes big.
    • longs are atleast 4 bytes big.
      • shorts are never bigger than ints.
        • ints are never bigger than longs.

                    Compiler    short        int         long   
              16-bit (Turbo C/C++)           2      2      4
              32-bit (Visual Studio )           2      4      4



          => long Variables:
          • long variables which hold long Integers are declared using the keyword long.
          Example: 
                         long int a;
                         long int xyz; 

          • long integers causes the Program to run a bit slower, but the Range of values that we can use is Expanded tremendously. 
          • The value of long Integer typically can vary from  -2147483648  to  2147483647.
          => short Variables:
          • short variables which hold short integers are declared using keyword short as shown
          Example:
                        short int b;
                        short int cool;
          • short needs Less space in Memory and thus helps in speed of Program Execution.
          NOTE: C allows to write short int to short and of long int to long. So declaration made very easy.

          Example:
                         long a;
                         long xyz;
                         short b;
                         short cool ;

          NOTE: Sometimes we come across situations where the constant is small enough to be an int , but still we want to give it as much storage as a long. In such cases , we add the suffix 'L' or '1' at the end of the number i.e 23L

                                                                         That's All

          0 Response to "Difference Between an Integer , short and long Variables"

          Post a Comment

          Popular Posts

          Label

          1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag