CyberiaPC.com Main Page




Learning C++

Understanding the Different Types of Variables/ Learn the Basics
 
 
Data Types (variables)
The Terminology
Declaring Data Types and Using the Various Operators
Rules for Naming Data Types
C++ Libraries

Data Types (variables)

When you start learning any programming language, it is essential that you familiarize yourself with the different types of variables for that language.  Variables are simply containers that hold numbers or characters in memory.  The name 'variable' means that the values in these "containers" can be changed at any time.  Variables make it extremely easy for you to pass information from one control to another in your program.  For example, if you want to determine if a user can drive a car legally or not, you could obtain their age from them, pass it on to another function that does the calculation and then display the result.  Here are the main types of data types:

Data Type Description Decimal Precision Storage size
Integer Stores only whole numbers from -32,768 to 32,767. 0 2 bytes
Long Integer Stores only whole numbers from -2,147,483,648 to 2,147,483,647. 0 4 bytes
Double Stores numbers from -1.79769313486231E308 to -4.94065645841247E-324 for negative values and from 1.79769313486231E308 to 4.94065645841247E-324 for positive values. 15 8 bytes
String Stores a series of characters.  Note that the default string library for Microsoft VC++ 6 will be used in this tutorial. n/a -

When a data type from the table above is preceded by the keyword const, then that tells the compiler (the program you are writing your C++ program in) that this certain variable will not change throughout the application.  Making certain variables constants is considered a good thing, since it gives the compiler more chance to find your mistakes for you, as well as making your code more easier to maintain and update later on.

{Go Back To C++ Lessons Page}