Академический Документы
Профессиональный Документы
Культура Документы
1 Data Structures
Overview
WHAT IS DATA?
In the MOST FUNDAMENTAL AND PRIMITIVE SENSE THE
VARIOUS PROPERTIES OR ATTRIBUTES ASSOCIATED WITH
SOME OBJECT, FACT OR ASSUMPTION OR WITH A
COLLECTION OF OBJECTS AND/OR FACTS AND/OR
ASSUMPTIONS IS CALEED “DATA”.
The same data may appear in different forms depending upon how and
when it is viewed by a human or machine. For example, signals
emanating from a network connection wire and entering a computer’s
port are an instance of data, because the signals (carrying email
messages, web pages etc.) are being electronically perceived by the
computer, and the physical characteristics (such as frequency,
amplitude etc.) of the signals would be used by the computer software to
extract more sophisticated data (web page contents, color, email
message text, networking protocol parameters etc.) from them.
There is also a very special data type in C which is called the pointer
data type. The pointer data type can be used to store the addresses of
variables of the data types already mentioned in the memory of a
computer. Although a pointer data type contains an unsigned integer,
and is therefore numeric in nature, it must be used for the purpose of
storing memory addresses only.
Ds_tpx.4 IN C, A VALUE (NUMERIC OR CHARACTER) CANNOT BE
STORED IN A DATA TYPE UNTIL AND UNLESS THERE IS A
“VARIABLE” OF THAT DATA TYPE AVAILABLE. A VARIABLE
IS SIMPLY A “NAME” GIVEN TO SOME MEMORY LOCATION
WHERE THE VALUE TO BE STORED WILL BE STORED.
VRIABLES IN C CAN HAVE NAMES CONSISTING OF
ALPHANUMERIC CHARACTERS(capital or small letters, digits 0-9,
and the underscore _). THE FIRST CHARACTER IN THE NAME OF
A VARIABLE MUST BE A LETTER. EXAMPLES OF VRIABLE
NAMES ARE alpha45, total_amount, CustomerName, ABC_243 ETC.
How can a variable be made available for storing some value? The
answer is simple! By DECLARING the variable. For example 4
variables of the int data type may be declared as follows:
In the above example 4 different variables of the int data type have been
declared. The names of the variables are myvar, x1, abc25, and
sum_total. Each of these variables is now available for storing an integer
by using the assignment statement of C, as shown below:
myvar = 28;
x1 = 7 + 92;
abc25 = myvar + 13;
The 4 float variables can now be used to store real numbers, as shown
below:
fx1 = 409.56201;
bulk_val = 0.5796;
It is getting … Ah!... a bit late! So much has been mentioned about how
structures and arrays in C may be used to build data structures, but no
definition of what a structure or array is has been given!
After this, values may be assigned to elements of st1 and st2 in the
following manner:
st1.a = 10;
st1.x3 = 2.46;
st2.ch = ‘B’;
st2.r = 67.9043;
st1.r = 9.00762;
st1.ch = ‘F’;
…
…
Thus, in order to access the elements of a variable representing a
structure, the “.” (i.e. dot) is used as shown in the above example.
So much for structures. Now what is an array? An array in C is simply
Ds_tpx.7 an ordered sequence of n (n = 1, 5, 8, 15, 50, 70, 100, 400, 1000 etc.)
elements of the SAME DATA TYPE. Each element of the array is
identified by the ARRAY NAME and an integer called its index which
increases by 1 for each successive element, starting from 0. The highest
index value is determined by the NUMBER OF ELEMENTS IN THE
ARRAY WHICH IS SPECIFIED AT THE TIME OF DECLARING
THE ARRAY AS A VARIABLE. If the number of elements in the
array is, for example, 60, the values of the array index would range
from 0 to 59. In order to use an array and assign values to its individual
elements, the array must first be declared. An array may be declared as
a variable as shown by the following example:
In the above example 2 arrays called abc and test consisting of 1300
and 40 integers, respectively, and 2 arrays called name and address,
consisting of 30 and 100 elements, respectively, of type char have been
declared.
abc[0] = 3057;
abc[578] = 21984;
test[31] = 19820;
name[0] = ‘A’;
name[1] = ‘l’;
name[2] = ‘i’;
name[3] = ‘\0’;
strcpy(address, “A-496, 4th Street, Middletown, Cronton”);
…
…