Data Types and Operations
Data Types and Operations
GET 261
Generally all software is divided into two, namely:
1) DATA
2) PROGRAM
form of text documents, images, audio clips, software programs, or other types of data.
Computer data may be processed by the computer's Central Processing Unit and is stored
PROGRAM: These are collections of instructions for manipulating data. Variables are
When computer programs store data in variables, each variable must be assigned a
specific data type. A data type in a programming language can also be said to be a set
Some programming languages require the programmer to define the data type of a variable
before assigning it a value. Other languages can automatically assign a variable's data type
If the variable "var1" is created with the value "1.25," the variable would be
If the variable is set to "Hello world!," the variable would be assigned a string data
type.
Most programming languages allow each variable to store a single data type.
Therefore, if the variable's data type has already been set to an integer, assigning
string data to the variable may cause the data to be converted to an integer format
For example: Adding two whole numbers 10 & 20, which can be done simply as follows −
10 + 20
Let's take another problem where we want to add two decimal numbers 10.50 & 20.50, which
10.50 + 20.50
The two examples are straightforward. Now let's take another example where we want to
record student information in a file. Here we would like to record the following information:
−
A typical student record in a file will look like this:
Sex: Female
Age: 13 years
Section: f
whereas the third example is dealing with a mix of different data. For instance:
Student name "Zara Ali" is a sequence of characters which is also called a string.
•Student class "6th" has been represented by a mix of whole number and a string of two
such as strings, characters, whole numbers (integers), and decimal numbers (floating point
numbers).
need to specify its type clearly; otherwise the computer does not understand how different
specify different data types. Following are the list of basic data type
1) Integer
2) Floating point
3) Real
4) string
5) Complex
6) Logical
7) Character
INTEGER DATA TYPE
some finite subset of the mathematical data. Integral data types may be of different sizes
(bits). The size of the grouping varies so the set of integer sizes available varies between
zero. Therefore, the numbers 10, 0, -25, and 5,148 are all integers. Integers cannot have
decimal places.
Integers are the most commonly used data type in computer programming. For
example, whenever a number is being incremented, such as within a "for loop" or "while
loop," an integer is used. Integers are also used to determine an item's location within an
array.
When two integers are added, subtracted, or multiplied, the result is also an integer.
NOTE: when one integer is divided into another, the result may be an integer or a
equals 1.5, which contains a fraction. Decimal numbers may either be rounded or
The Character data type is a single two-byte (16-bit) Unicode character. If a variable
For example:
To store alphanumeric text, such as letters, numbers, spaces, symbols, and punctuation, use
As the name implies, floating point numbers are numbers that contain floating decimal
points. For example, the numbers 5.5, 0.001, and -2,345.6789 are floating point numbers.
Computers recognize real numbers that contain fractions as floating point numbers.
calculation." Older computers used to have a separate floating point unit (FPU) that
handled these calculations, but now the FPU is typically built into the computer's CPU.
STRING DATA TYPE
A string is a data type used in programming, such as an integer and floating point unit, but is
used to represent text rather than numbers. It is comprised of a set of characters that can also
contain spaces and numbers. For example, the word "hamburger" and the phrase "I ate 3
hamburgers" are both strings. Even "12345" could be considered a string, if specified
correctly. Typically, programmers must enclose strings in quotation marks for the data to
other data. If the values are the same, the test returns a value of true,
Option1 and Option2 are being treated as strings. Therefore the test is
false.
REAL DATA TYPE
A 'Real' data type is numerical data which contains decimal numbers. It would be used when
extra detail is required and a whole number would not provide enough information.
type of quantity being measured e.g. meters, Kilograms, Celsius. If you use this data type
then you need to put the unit of measurement after the field name as it was done above.
COMPLEX DATA TYPE
Complex data type can also be referred to as composite data type: A complex variable
support a complex data type usually provide special syntax for building such values,
and extend the basic arithmetic operations ('+', '−', '×', '÷') to act on them. These
To store data that has only two values true or false, use the Logical data type when you
want an efficient way to represent Boolean expressions or when comparing two or more
generally like functions, but which differ syntactically or semantically from usual functions.
Common simple examples include arithmetic (addition with +, comparison with >;) and
More involved examples include assignment (usually = or :=), field access in a record
or object (usually .), and the scope resolution operator (often ::). Languages usually define a
Assume variable A holds 10 and variable B holds 20, then a typical C program for this instruction will look like this:
#include <stdio.h>
main() {
int a, b, c;
a = 10;
b = 20;
c = a + b;
printf( "Value of c = %d\n", c);
c = a - b;
printf( "Value of c = %d\n", c);
c = a * b;
printf( "Value of c = %d\n", c);
c = b / a;
printf( "Value of c = %d\n", c);
c = b % a;
printf( "Value of c = %d\n", c);
}