Posts

Showing posts with the label Arrays

Arrays in C++

Arrays are among the most basic data structures in computer science. An array is simply, a data storing entity that stores homogenous data values. For example, if we need to store a sequence of integer values such as 3, 5, 7, 9 and 11 then rather than declaring 5 integer variables, we can use 1 integer array to store all the five values. int array[] = {3, 5, 7, 9, 11}; location 0, accessed by array[0] contains the value 3 location 1, accessed by array[1] contains the value 5 location 2, accessed by array[2] contains the value 7 location 3, accessed by array[3] contains the value 9 location 4, accessed by array[4] contains the value 11 The int before array, in array declaration describes the type of data that the array can store. It can be any valid data type such as int, string, char, float, etc. Arrays can be single dimensional or multi dimensional. The array used in the example above is single dimensional. A two-dimensional array with 2 rows and 3 columns can be de...