PROBLEM SOLVING THROUGH PROGRAMMING (18ESCS01)
1
UNIT-3: ARRAYS & STRINGS
- ARRAYS
- DECLARATION OF ARRAYS
- INITIALIZATION OF ARRAYS
- ONE-DIMENTIONAL & TWO-DIMENTIONAL ARRAYS
- STRINGS
- STRING OPERATIONS
- STRING ARRAYS
- SIMPLE OPERATIONS – SORTING & SEARCHING –
MATRIX OPERATIONS
2
ARRAYS - Array is a data structure that can store a fixed-size sequential collection of elements of the same type.
- An array is defined as finite ordered collection of homogenous data (of same type), stored in contiguous memory locations.
- The lowest address corresponds to the first element and the highest address to the last element.
- Examples where arrays are applicable:
3
DECLARATION OF ARRAYS - General form of array declaration is:
- int -> is the data type,
arr ->is the name of the array and
10 -> is the size of array [0 to size – 1]. It means
array ’arr’ can only contain 10 elements of int type.
data-type array_name[array_size];
/* Example of array declaration */ int arr[10];
INITIALIZATION OF ARRAYS - We can initialize an array in ‘C’ either one by one or using a single statement as:
- The number of values between braces { } cannot be larger than the number of elements that we declare for the array between square brackets [ ].
int a[5] = {10, 20, 30, 40, 50};
float balance[5] = {1000.0, 2.0, 3.4, 7.0, 50.0};
Do'stlaringiz bilan baham: |