Saturday, July 17, 2010

C++: Introducing data

By this time, I'm sure you know the meaning behind the sample Hello world
program - how to declare start and end of a program, how to display
something to the user and so forth. Let's now take a look at one of the
fundamental things about programming: declaring and working with variables,
or data.

Data is things that the program use to process information, such as our
names, age and even a group of car models. C++ and other programming
languages offer a vast number of built-in data types and many of these
programming languages (called object-oriented languages) offers a way for us
to create our own custom data types to suit our needs. In C++, there are
five fundamental, or built-in data types: integers, floating point numbers,
characters, Boolean (true/false) statements and pointers (addresses of

An integer is a whole number e.g. 0, 20, -10, etc. A floating point number
is the technical name for decimal numbers e.g. 0.5, 2.7, -1.003, etc. A
character is, as the name suggests, used to store one letter or symbole at a
time. A Boolean statement from Charles Boole (inventor of Boolean Algebra)
stores true or false statements. A pointer is the address of a data item on
physical memory and it requires special discussion on it separate from other
data types. In addition to these four or five data types, there are a number
of variations of these, including "short" - used to store short integers
from -32,768 to 32,767 (or 16-bit numbers), double (called double precision
floating point because it is better at storing 64-bit decimal numbers and
have greater accuracy) and string (a group of characters). For our
discussion right now, let us focus on the above four - integers (or just
called int), characters (or char), bool and float/double, with an example of
how to declare such variables in the next installment.

Note: Data is the plural of "datum." Also, for better accuracy, people tend
to use double when using decimals. Pointers are useful when we work with
memory addresses and is not really useful now - it becomes relevant as we
get into designing our own data types. The "string" variable requires the
presence of "string" library.

No comments:

Post a Comment