0% found this document useful (0 votes)
16 views8 pages

Chapter 0: C LANGUAGE: 3. Arrays

The document discusses arrays and pointers in C language. It notes that arrays are used to process multiple elements of the same data type, and each element has a unique memory address. Arrays can be accessed and manipulated using pointers, where a pointer to the appropriate data type (e.g. integer pointer for integer arrays) is used. Two-dimensional arrays and pointer arrays are also introduced. Finally, structures are discussed as a way to process multiple data types as a single entity, and structure pointers allow processing structures using pointers.

Uploaded by

Mouhamad Bazzi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Chapter 0: C LANGUAGE: 3. Arrays

The document discusses arrays and pointers in C language. It notes that arrays are used to process multiple elements of the same data type, and each element has a unique memory address. Arrays can be accessed and manipulated using pointers, where a pointer to the appropriate data type (e.g. integer pointer for integer arrays) is used. Two-dimensional arrays and pointer arrays are also introduced. Finally, structures are discussed as a way to process multiple data types as a single entity, and structure pointers allow processing structures using pointers.

Uploaded by

Mouhamad Bazzi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like