SlideShare a Scribd company logo
Homework Assignment – Array Technical Document
Write a technical document that describes the structure and use of arrays. The document should
be 3 to 5 pages and include an Introduction section, giving a brief synopsis of the document and
arrays, a Body section, describing arrays and giving an annotated example of their use as a
programming construct, and a conclusion to revisit important information about arrays described
in the Body of the document. Some suggested material to include:
Declaring arrays of various types
Array pointers
Printing and processing arrays
Sorting and searching arrays
Multidimensional arrays
Indexing arrays of various dimension
Array representation in memory by data type
Passing arrays as arguments
If you find any useful images on the Internet, you can use them as long as you cite the source in
end notes.
Solution
Array is a collection of variables of the same type that are referenced by a common name.
Specific elements or variables in the array are accessed by means of index into the array.
If taking about C, In C all arrays consist of contiguous memory locations. The lowest address
corresponds to the first element in the array while the largest address corresponds to the last
element in the array.
C supports both single and multi-dimensional arrays.
1) Single Dimension Arrays:-
Syntax:- type var_name[size];
where type is the type of each element in the array, var_name is any valid identifier, and size is
the number of elements in the array which has to be a constant value.
*Array always use zero as index to first element.
The valid indices for array above are 0 .. 4, i.e. 0 .. number of elements - 1
For Example :- To load an array with values 0 .. 99
int x[100] ;
int i ;
for ( i = 0; i < 100; i++ )
x[i] = i ;
To determine to size of an array at run time the sizeof operator is used. This returns the size in
bytes of its argument. The name of the array is given as the operand
size_of_array = sizeof ( array_name ) ;
2) Initialisg array:-
Arrays can be initialised at time of declaration in the following manner.
type array[ size ] = { value list };
For Example :-
int i[5] = {1, 2, 3, 4, 5 } ;
i[0] = 1, i[1] = 2, etc.
The size specification in the declaration may be omitted which causes the compiler to count the
number of elements in the value list and allocate appropriate storage.
For Example :- int i[ ] = { 1, 2, 3, 4, 5 } ;
3) Multidimensional array:-
Multidimensional arrays of any dimension are possible in C but in practice only two or three
dimensional arrays are workable. The most common multidimensional array is a two
dimensional array for example the computer display, board games, a mathematical matrix etc.
Syntax :type name [ rows ] [ columns ] ;
For Example :- 2D array of dimension 2 X 3.
int d[ 2 ] [ 3 ] ;
A two dimensional array is actually an array of arrays, in the above case an array of two integer
arrays (the rows) each with three elements, and is stored row-wise in memory.
For Example :- Program to fill in a 2D array with numbers 1 to 6 and to print it out row-wise.
#include
void main( )
{
int i, j, num[2][3] ;
for ( i = 0; i < 2; i++ )
for ( j = 0; j < 3; j ++ )
num[i][j] = i * 3 + j + 1 ;
for ( i = 0; i < 2; i++ )
{
for ( j = 0; j < 3; j ++ )
printf("%d ",num[i][j] ) ;
printf(" " );
}
4) Array of Strings:-
Array of strings is in fact a two dimensional array of characters but it is more useful to view this
as an array of individual single dimension character arrays or strings.
For Example :-
char str_array[ 10 ] [ 30 ] ;
where the row index is used to access the individual row strings and where the column index is
the size of each string, thus str_array is an array of 10 strings each with a maximum size of 29
characters leaving one extra for the terminating null character.
For Example :- Program to read strings into str_array and print them out character by character.
#include
char str_array[10][30] ;
void main()
{
int i, j ;
puts("Enter ten strings ") ;
for ( i = 0 ; i < 10; i++ ) // read in as strings so a single for loop suffices
{
printf( " %d : ", i + 1) ;
gets( str_array[i] ) ;
}
for ( i = 0; i < 10; i++ )//printed out as individual chars so a
{ // nested for loop structure is required
for ( j=0; str_array[i][j] != '0' ; j++ )
putchar ( str_array[i][j] ) ;
putchar( ' ' ) ;
}
}
}
5) Arrays as arguments to functions :-
In C it is impossible to pass an entire array as an argument to a function -- instead the address of
the array is passed as a parameter to the function.
The name of an array without any index is the address of the first element of the array and hence
of the whole array as it is stored contiguously. However we need to know the size of the array in
the function - either by passing an extra parameter or by using the sizeof operator..
For Example :-
void main()
{
int array[20] ;
func1( array ) ;/* passes pointer to array to func1 */
}
In the function receiving the array the formal parameters can be declared in one of three almost
equivalent ways as follows :-
func1 ( int x[10] ) {
}
func1 ( int x[ ] ) {
}
func1 ( int *x ) {
}
6) Passing Multidimensional Arrays :-
Function calls with multi-dimensional arrays will be the same as with single dimension arrays as
we will still only pass the address of the first element of the array.
However to declare the formal parameters to the function we need to specify all but one of the
dimensions of the array so that it may be indexed properly in the function.
For Example :-
2D array of doubles :- double x[10][20] ;
Call func1 with x a parameter :- func1( x ) ;
Declaration in func1 :- func1( double y[ ][20] ) {
}
7) Pointers and Arrays:-
There is a very close relationship between pointer and array notation in C. As we have seen
already the name of an array ( or string ) is actually the address in memory of the array and so it
is essentially a constant pointer.
For Example :-
char str[80], *ptr ;
ptr = str ;/* causes ptr to point to start of string str */
ptr = &str[0] ; /* this performs the same as above */
It is illegal however to do the following
str = ptr ; /* illegal */
as str is a constant pointer and so its value i.e. the address it holds cannot be changed.
Instead of using the normal method of accessing array elements using an index we can
use pointers in much the same way to access them as follows.
char str[80], *ptr , ch;
ptr = str ; // position the pointer appropriately
*ptr = 'a' ; // access first element i.e. str[0]
ch = *( ptr + 1 ) ; // access second element i.e. str[1]
Thus *( array + index ) is equivalent to array[index].
8) Arrays of Pointer:-
It is possible to declare arrays of pointers in C the same as any other 'type'. For example
int *x[10] ;
declares an array of ten integer pointers.
To make one of the pointers point to a variable one might do the following.
x[ 2 ] = &var ;
To access the value pointed to by x[ 2 ] we would do the following
*x[ 2 ]
which simply de-references the pointer x[ 2 ] using the * operator.
Passing this array to a function can be done by treating it the same as a normal array which
happens to be an array of elements of type int *.
9) Searching and sorting in array:-
a) Sequential search :-
To search the array sequentially, we may use the algorithm
Algorithm:-
int function SequentialSearch (Array A, int Lb, int Ub, int Key);
begin
for i = Lb to Ub do
if A(i) = Key
then
return i;
return
b) Binary Search:-
If the data is sorted, a binary search is usefull
Algorithm:-
int function BinarySearch (Array A, int Lb, int Ub, int Key);
begin
do forever M = (Lb + Ub)/2; if (Key < A[M]) then Ub = M - 1;
else if (Key > A[M]) then Lb = M + 1;
else return M;
if (Lb > Ub) then return -1;
end;
9) Sorting:-
Sorting Summary
Selection Sort
The idea behind selection sort is:
The approach is as follows:
Note that after i iterations, A[0] through A[i-1] contain their final values (so after N iterations,
A[0] through A[N-1] contain their final values and we're done!)
Here's the code for selection sort:
Insertion Sort
The idea behind insertion sort is:
Merge Sort
As mentioned above, merge sort takes time O(N log N), which is quite a bit better than the two
O(N2) sorts described above (for example, when N=1,000,000, N2=1,000,000,000,000, and N
log2 N = 20,000,000; i.e., N2 is 50,000 times larger than N log N!).
The key insight behind merge sort is that it is possible to merge two sorted arrays, each
containing N/2 items to form one sorted array containing N items in time O(N). To do this
merge, you just step through the two arrays, always choosing the smaller of the two values to put
into the final array
Quick Sort
Quick sort (like merge sort) is a divide and conquer algorithm: it works by creating two problems
of half size, solving them recursively, then combining the solutions to the small problems to get a
solution to the original problem. However, quick sort does more work than merge sort in the
"divide" part, and is thus able to avoid doing any work at all in the "combine" part!
The idea is to start by partitioning the array: putting all small values in the left half and putting
all large values in the right half.
Hope I tryed to covered most of your points you can pickup this points and just write neet and
clean document with propere headings.array[0]12loc 1000array[1]-345loc 1004array[2]342loc
1008array[3]-3000loc 1012array[4]23455loc 1016

More Related Content

PPT
Basics of Data structure using C describing basics concepts
shanthidl1
 
PPTX
Chapter 13.pptx
AnisZahirahAzman
 
PPT
Arrays
swathi reddy
 
PDF
Array&amp;string
chanchal ghosh
 
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
PDF
Cunit3.pdf
zeenatparveen24
 
PPTX
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
PPT
Array THE DATA STRUCTURE. ITS THE STRUCT
duttasoumyajit5
 
Basics of Data structure using C describing basics concepts
shanthidl1
 
Chapter 13.pptx
AnisZahirahAzman
 
Arrays
swathi reddy
 
Array&amp;string
chanchal ghosh
 
Unit4pptx__2024_11_ 11_10_16_09.pptx
GImpact
 
Cunit3.pdf
zeenatparveen24
 
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
Array THE DATA STRUCTURE. ITS THE STRUCT
duttasoumyajit5
 

Similar to Homework Assignment – Array Technical DocumentWrite a technical .pdf (20)

PPTX
Module_3_Arrays - Updated.pptx............
ChiragKankani
 
DOC
Arrays and Strings
Dr.Subha Krishna
 
PDF
Array in C full basic explanation
TeresaJencyBala
 
PPTX
3.ArraysandPointers.pptx
FolkAdonis
 
PPTX
ppt on arrays in c programming language.pptx
AmanRai352102
 
PPTX
Arrays & Strings
Munazza-Mah-Jabeen
 
PPTX
Array 2 hina
heena94
 
PPT
C programming , array 2020
Osama Ghandour Geris
 
PDF
Arrays-Computer programming
nmahi96
 
PPTX
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
PPTX
Arrays
shillpi29
 
PDF
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
PPTX
Array
PralhadKhanal1
 
PPTX
unit 2.pptx
researchgrad82
 
PPTX
Arrays basics
sudhirvegad
 
PPT
Arrays Basics
Nikhil Pandit
 
PDF
Unit 4
SHIKHA GAUTAM
 
PDF
Arrays
ViniVini48
 
PPT
Arrays
SARITHA REDDY
 
Module_3_Arrays - Updated.pptx............
ChiragKankani
 
Arrays and Strings
Dr.Subha Krishna
 
Array in C full basic explanation
TeresaJencyBala
 
3.ArraysandPointers.pptx
FolkAdonis
 
ppt on arrays in c programming language.pptx
AmanRai352102
 
Arrays & Strings
Munazza-Mah-Jabeen
 
Array 2 hina
heena94
 
C programming , array 2020
Osama Ghandour Geris
 
Arrays-Computer programming
nmahi96
 
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
Arrays
shillpi29
 
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
unit 2.pptx
researchgrad82
 
Arrays basics
sudhirvegad
 
Arrays Basics
Nikhil Pandit
 
Arrays
ViniVini48
 
Ad

More from aroraopticals15 (20)

PDF
For a given H0 and level of significance, if you reject the H0 for a.pdf
aroraopticals15
 
PDF
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
aroraopticals15
 
PDF
Evaluate the decision to have a computer usage policy and the potent.pdf
aroraopticals15
 
PDF
(java) eclipse PleaseDevelop an application that implements a pro.pdf
aroraopticals15
 
PDF
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
aroraopticals15
 
PDF
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
aroraopticals15
 
PDF
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
aroraopticals15
 
PDF
Write short descriptive answer to the following questions Discuss wh.pdf
aroraopticals15
 
PDF
Why should anyone else care about what I do with my sewage on my own .pdf
aroraopticals15
 
PDF
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
aroraopticals15
 
PDF
Which of the following used historicalcomparative methods in their .pdf
aroraopticals15
 
PDF
Which of following is not a class of the phylum platyhelminthes Tre.pdf
aroraopticals15
 
PDF
What is wrong with this code Please fix.code#include stdio.h.pdf
aroraopticals15
 
PDF
What are two ways that meiosis could produce gametes that contai.pdf
aroraopticals15
 
PDF
what is the process in society that made this change to advertising .pdf
aroraopticals15
 
PDF
What is the best way to go about designing an Android AppSoluti.pdf
aroraopticals15
 
PDF
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
aroraopticals15
 
PDF
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
aroraopticals15
 
PDF
Two labs are being compared to determine if they are providing the sa.pdf
aroraopticals15
 
PDF
Todopackage hwk6; This class contains the configuration of a t.pdf
aroraopticals15
 
For a given H0 and level of significance, if you reject the H0 for a.pdf
aroraopticals15
 
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
aroraopticals15
 
Evaluate the decision to have a computer usage policy and the potent.pdf
aroraopticals15
 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
aroraopticals15
 
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
aroraopticals15
 
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
aroraopticals15
 
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
aroraopticals15
 
Write short descriptive answer to the following questions Discuss wh.pdf
aroraopticals15
 
Why should anyone else care about what I do with my sewage on my own .pdf
aroraopticals15
 
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
aroraopticals15
 
Which of the following used historicalcomparative methods in their .pdf
aroraopticals15
 
Which of following is not a class of the phylum platyhelminthes Tre.pdf
aroraopticals15
 
What is wrong with this code Please fix.code#include stdio.h.pdf
aroraopticals15
 
What are two ways that meiosis could produce gametes that contai.pdf
aroraopticals15
 
what is the process in society that made this change to advertising .pdf
aroraopticals15
 
What is the best way to go about designing an Android AppSoluti.pdf
aroraopticals15
 
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
aroraopticals15
 
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
aroraopticals15
 
Two labs are being compared to determine if they are providing the sa.pdf
aroraopticals15
 
Todopackage hwk6; This class contains the configuration of a t.pdf
aroraopticals15
 
Ad

Recently uploaded (20)

PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 

Homework Assignment – Array Technical DocumentWrite a technical .pdf

  • 1. Homework Assignment – Array Technical Document Write a technical document that describes the structure and use of arrays. The document should be 3 to 5 pages and include an Introduction section, giving a brief synopsis of the document and arrays, a Body section, describing arrays and giving an annotated example of their use as a programming construct, and a conclusion to revisit important information about arrays described in the Body of the document. Some suggested material to include: Declaring arrays of various types Array pointers Printing and processing arrays Sorting and searching arrays Multidimensional arrays Indexing arrays of various dimension Array representation in memory by data type Passing arrays as arguments If you find any useful images on the Internet, you can use them as long as you cite the source in end notes. Solution Array is a collection of variables of the same type that are referenced by a common name. Specific elements or variables in the array are accessed by means of index into the array. If taking about C, In C all arrays consist of contiguous memory locations. The lowest address corresponds to the first element in the array while the largest address corresponds to the last element in the array. C supports both single and multi-dimensional arrays. 1) Single Dimension Arrays:- Syntax:- type var_name[size]; where type is the type of each element in the array, var_name is any valid identifier, and size is the number of elements in the array which has to be a constant value. *Array always use zero as index to first element. The valid indices for array above are 0 .. 4, i.e. 0 .. number of elements - 1 For Example :- To load an array with values 0 .. 99 int x[100] ; int i ;
  • 2. for ( i = 0; i < 100; i++ ) x[i] = i ; To determine to size of an array at run time the sizeof operator is used. This returns the size in bytes of its argument. The name of the array is given as the operand size_of_array = sizeof ( array_name ) ; 2) Initialisg array:- Arrays can be initialised at time of declaration in the following manner. type array[ size ] = { value list }; For Example :- int i[5] = {1, 2, 3, 4, 5 } ; i[0] = 1, i[1] = 2, etc. The size specification in the declaration may be omitted which causes the compiler to count the number of elements in the value list and allocate appropriate storage. For Example :- int i[ ] = { 1, 2, 3, 4, 5 } ; 3) Multidimensional array:- Multidimensional arrays of any dimension are possible in C but in practice only two or three dimensional arrays are workable. The most common multidimensional array is a two dimensional array for example the computer display, board games, a mathematical matrix etc. Syntax :type name [ rows ] [ columns ] ; For Example :- 2D array of dimension 2 X 3. int d[ 2 ] [ 3 ] ; A two dimensional array is actually an array of arrays, in the above case an array of two integer arrays (the rows) each with three elements, and is stored row-wise in memory. For Example :- Program to fill in a 2D array with numbers 1 to 6 and to print it out row-wise. #include void main( ) { int i, j, num[2][3] ; for ( i = 0; i < 2; i++ ) for ( j = 0; j < 3; j ++ ) num[i][j] = i * 3 + j + 1 ; for ( i = 0; i < 2; i++ ) { for ( j = 0; j < 3; j ++ ) printf("%d ",num[i][j] ) ; printf(" " );
  • 3. } 4) Array of Strings:- Array of strings is in fact a two dimensional array of characters but it is more useful to view this as an array of individual single dimension character arrays or strings. For Example :- char str_array[ 10 ] [ 30 ] ; where the row index is used to access the individual row strings and where the column index is the size of each string, thus str_array is an array of 10 strings each with a maximum size of 29 characters leaving one extra for the terminating null character. For Example :- Program to read strings into str_array and print them out character by character. #include char str_array[10][30] ; void main() { int i, j ; puts("Enter ten strings ") ; for ( i = 0 ; i < 10; i++ ) // read in as strings so a single for loop suffices { printf( " %d : ", i + 1) ; gets( str_array[i] ) ; } for ( i = 0; i < 10; i++ )//printed out as individual chars so a { // nested for loop structure is required for ( j=0; str_array[i][j] != '0' ; j++ ) putchar ( str_array[i][j] ) ; putchar( ' ' ) ; } } } 5) Arrays as arguments to functions :- In C it is impossible to pass an entire array as an argument to a function -- instead the address of the array is passed as a parameter to the function. The name of an array without any index is the address of the first element of the array and hence of the whole array as it is stored contiguously. However we need to know the size of the array in the function - either by passing an extra parameter or by using the sizeof operator.. For Example :-
  • 4. void main() { int array[20] ; func1( array ) ;/* passes pointer to array to func1 */ } In the function receiving the array the formal parameters can be declared in one of three almost equivalent ways as follows :- func1 ( int x[10] ) { } func1 ( int x[ ] ) { } func1 ( int *x ) { } 6) Passing Multidimensional Arrays :- Function calls with multi-dimensional arrays will be the same as with single dimension arrays as we will still only pass the address of the first element of the array. However to declare the formal parameters to the function we need to specify all but one of the dimensions of the array so that it may be indexed properly in the function. For Example :- 2D array of doubles :- double x[10][20] ; Call func1 with x a parameter :- func1( x ) ; Declaration in func1 :- func1( double y[ ][20] ) { } 7) Pointers and Arrays:- There is a very close relationship between pointer and array notation in C. As we have seen already the name of an array ( or string ) is actually the address in memory of the array and so it is essentially a constant pointer. For Example :- char str[80], *ptr ; ptr = str ;/* causes ptr to point to start of string str */ ptr = &str[0] ; /* this performs the same as above */ It is illegal however to do the following str = ptr ; /* illegal */ as str is a constant pointer and so its value i.e. the address it holds cannot be changed. Instead of using the normal method of accessing array elements using an index we can use pointers in much the same way to access them as follows.
  • 5. char str[80], *ptr , ch; ptr = str ; // position the pointer appropriately *ptr = 'a' ; // access first element i.e. str[0] ch = *( ptr + 1 ) ; // access second element i.e. str[1] Thus *( array + index ) is equivalent to array[index]. 8) Arrays of Pointer:- It is possible to declare arrays of pointers in C the same as any other 'type'. For example int *x[10] ; declares an array of ten integer pointers. To make one of the pointers point to a variable one might do the following. x[ 2 ] = &var ; To access the value pointed to by x[ 2 ] we would do the following *x[ 2 ] which simply de-references the pointer x[ 2 ] using the * operator. Passing this array to a function can be done by treating it the same as a normal array which happens to be an array of elements of type int *. 9) Searching and sorting in array:- a) Sequential search :- To search the array sequentially, we may use the algorithm Algorithm:- int function SequentialSearch (Array A, int Lb, int Ub, int Key); begin for i = Lb to Ub do if A(i) = Key then return i; return b) Binary Search:- If the data is sorted, a binary search is usefull Algorithm:- int function BinarySearch (Array A, int Lb, int Ub, int Key); begin do forever M = (Lb + Ub)/2; if (Key < A[M]) then Ub = M - 1; else if (Key > A[M]) then Lb = M + 1; else return M; if (Lb > Ub) then return -1;
  • 6. end; 9) Sorting:- Sorting Summary Selection Sort The idea behind selection sort is: The approach is as follows: Note that after i iterations, A[0] through A[i-1] contain their final values (so after N iterations, A[0] through A[N-1] contain their final values and we're done!) Here's the code for selection sort: Insertion Sort The idea behind insertion sort is: Merge Sort As mentioned above, merge sort takes time O(N log N), which is quite a bit better than the two O(N2) sorts described above (for example, when N=1,000,000, N2=1,000,000,000,000, and N log2 N = 20,000,000; i.e., N2 is 50,000 times larger than N log N!). The key insight behind merge sort is that it is possible to merge two sorted arrays, each containing N/2 items to form one sorted array containing N items in time O(N). To do this merge, you just step through the two arrays, always choosing the smaller of the two values to put into the final array Quick Sort Quick sort (like merge sort) is a divide and conquer algorithm: it works by creating two problems of half size, solving them recursively, then combining the solutions to the small problems to get a solution to the original problem. However, quick sort does more work than merge sort in the "divide" part, and is thus able to avoid doing any work at all in the "combine" part! The idea is to start by partitioning the array: putting all small values in the left half and putting all large values in the right half. Hope I tryed to covered most of your points you can pickup this points and just write neet and clean document with propere headings.array[0]12loc 1000array[1]-345loc 1004array[2]342loc 1008array[3]-3000loc 1012array[4]23455loc 1016