Documente Academic
Documente Profesional
Documente Cultură
Arrays in C
Definitions:
Array : a finite ordered set of homogenous elements
Finite: specific number of elements.
Ordered: elements in array are arranged .
Homogenous: all elements in array must be the same type.
1 Fatemah Ba_hareth
Chapter 1 Arrays in C
if not the all elements have the same size, a different implementation must be used:
reserve a contiguous set of memory location. Each of which hold an address. The
contents of each memory location is the address of the varying-length array
element in some other portion of memory.
keep all fixed length portion of the elements in the contiguous array.
Arrays as Parameters:
Character strings in C:
Example:
"HELLO THERE" is an array of 12 characters.
(blank and \0 each counts as a character)
2 Fatemah Ba_hareth
Chapter 1 Arrays in C
Tow-Dimensional Arrays:
declaration in C:
Type arr_name [rows][cols];
Example: int a[3][5];
3 Fatemah Ba_hareth
Chapter 1 Arrays in C
array of pointers
float arr[10][5];
Calculate the address of:
• arr[4][2]
• arr[5][4]
• arr[7][3]
4 Fatemah Ba_hareth