Lec02 (Week 1) - CS 232 - Data Structure
Lec02 (Week 1) - CS 232 - Data Structure
Syntax
dataType arrayName[arraySize];
Example
Declaration Initialization Array Items
Syntax
dataType arrayName[arraySize] = {arrayItems};
Example
HOW TO ACCESS A SPECIFIC
ARRAY VALUE
Syntax
ArrayName[indexNum]
Example
The Output will be
200
USING LOOP IN AN ARRAY
THE OUTPUT WILL BE
ARRAY OPERATIONS IN
C++
In C++ you have to program the logic yourself for performing the insert,
delete, search update and traverse operations on C++ arrays.
Insert
The logic for insertion operation goes as follows:
loop through the array items
shift them to a greater index
add a new array item at a given index
In the following example, we have 5 items in the “my1starray” array, and
we want to add a new item just after the value of 200. This means we have
to shift all the items after 200 to a greater index, and then insert our new
value of 150.
THE OUTPUT WILL BE