Chapter 0: C LANGUAGE
3. ARRAYS
1. An array is a data structure
2. used to process multiple elements with the same data
type when a number of such elements are known.
3. An array is a composite data structure; that means it
had to be constructed from basic data types such as
array integers.
1. int a[5];
2. for(int i = 0;i<5;i++)
1. {a[i]=i; }
Chapter 0: C LANGUAGE
4. ADDRESS OF EACH ELEMENT IN AN
ARRAY
Each element of the array has a memory
address.
void printdetail(int a[])
{
for(int i = 0;i<5;i++)
{
cout<< "value in array “<< a[i] <<“ at address: “ << &a[i]);
}
Chapter 0: C LANGUAGE
5. ACCESSING & MANIPULATING AN
ARRAY USING POINTERS
– You can access an array element by using a pointer.
– If an array stores integers->use a pointer to integer to
access array elements.
Chapter 0: C LANGUAGE
6. ANOTHER CASE OF MANIPULATING AN
ARRAY USING POINTERS
The array limit is a pointer constant : cannot
change its value in the program.
It works correctly even using
int a[5]; int *b; a++ ???
a=b; //error
b=a; //OK
Chapter 0: C LANGUAGE
7. TWO-DIMENSIONAL ARRAY
int a[3][2];
Chapter 0: C LANGUAGE
8. POINTER ARRAYS
You can define a pointer array (similarly to an array of
integers).
In the pointer array, the array elements store the
pointer that points to integer values.
Chapter 0: C LANGUAGE
9. STRUCTURES
Structures are used when
you want to process data of
multiple data types
But you still want to refer to
the data as a single entity
Access data:
[Link]
e
Chapter 1: C LANGUAGE
10. STRUCTURE POINTERS
Process the structure using a structure pointer