1. Home
  2. Computing & Technology
  3. C / C++ / C#

C++ Handling Ints and Floats

By David Bolton, About.com

2 of 8

More about Ints

What is the biggest number an int can store?. Well it depends on the type of CPU but it is generally accepted as 32 bits. Because it can hold almost as many negative values as positive, the range of values is +/- 2-32 to 232 or -2,147,483,648 to +2,147,483,647.

This is for a signed int, but there is also an unsigned int that holds zero or positive. It has a range of 0 to 4,294,967,295. Just remember - unsigned ints don't need a sign (like + or -1) in front of them because they are always positive or 0.

Short Ints

There is a shorter int type, coincidentally called short int which use 16 bits (2 bytes). This holds numbers in the range -32768 to +32767. If you use a large umber of ints, you can possibly save memory by using short ints. It will not be any quicker, despite being half the size. 32 Bit CPUs fetch values from memory in blocks of 4 bytes at a time. I.e. 32 bits (Hence the name- 32 Bit CPU!). So fetching 16 bits still requires a 32 bit fetch.

There is a longer 64 bit called long long in C. Some C++ compilers while not supporting that type directly use an alternate name- e.g. both Borland and Microsoft use _int64. This has a range of -9223372036854775807 to 9223372036854775807 (signed) and 0 to 18446744073709551615 (unsigned).

As with ints there is an unsigned short int type that has a range of 0..65535.

Note: Some computer languages refer to 16 bits as a Word

On the next page : Learn about precision in floats.

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C++
  5. Learn C++ Programming
  6. More About Ints

©2009 About.com, a part of The New York Times Company.

All rights reserved.