DATA TYPES
In our last tutorial we learnt about variables, but
variables are declared using data types. So, this article talks about data
types and how they can be used in the declaration of variables. But before that
let’s look at this;
In our normal
lives, we sometimes obtain data and group them in categories for easy
identification. In this case, a certain category of data may have some
characteristics that others do not have.
The same idea is
applied in data types
Now let’s look
at the definition of data types;
DEFINITION:
Data types
refers to the classification of a particular type of information.
Data types in programming
1. Integer data types
2. String data types
3. Floating-point
4. Character data types
5. Boolean data types
Integer
An integer
is a positive or negative whole number (a number that has no fractional part).
The integer
data type stores positive or negative whole numbers.
Example; 2, 4,
-3, -5, 0.
Example of
non-integers;
3.2, 4.1
String
String is a
combination of characters
A variable
declared with the string data type can store data that consists of combination
of characters only.
Example; Klenam,
pack, joe@;
Floating
point
A
floating-point or float is a data type that is used to store floating -point
numbers
(Fractional numbers).
Example;
2.4, 5.8, 6.9
The floating-point
data type can also store whole numbers
Character
The keyword
“char” is used in the declaration of variables that holds characters;
Example; char alpha=a;
Here the
keyword “char” is used to declare the variable alpha and the character “a” has been assigned to it.
The
character data type can only represent single character;
Example of
characters;
Q,@,p,%,q.
Boolean
In programming you often need to know if
an expression is True or False
The Boolean data
type has only two values;
Ø True
Ø False
It is used to testify whether a condition is true or false.
DECLARATION
All the variables that a program is going to use in a program must be declared.
To declare variables the appropriate data type is written before the variable
name;
Syntax;
Data_type variable name;
Example:
Int name;
string joe;
char letter;

0 Comments