What is One Dimensional Array in Data Structure with Example
One-Dimensional Array or single Dimensional Array is one in which only one-subscript specification is needed to specify a particular element of the array. One dimensional array we can be declared as follows:-
data_type data_type is the type of element to be stored in the array
array_name array_name specify the name of the array, it may be given any type of name like other simple variables
Expression its specified the number of values to be stored in the array, arrays also know as subscripted values, the subscript value must be an integer value, therefore the subscript of the array starts from 0 onwards.
lets us see the example if the array declaration looks like follows:
where int:data type
then it implies the following to us:
therefore, the array will store ten integer values as given above expression, its name is “a”. it can be visualized as shown given below, see and understand carefully.
Data values are dummy values, you can understand after seeing the output, indexing starts from “0”.
To access fourth element from array int "a"
the fourth element = a; as you can see in the given above output.
therefore, The Subscript for fourth element is 3, because the lower bound of array is “0” (i.e. the array subscript starts from 0). and the upper bound will be 9. hence the size of array can defined as follows:
Let’s calculate the size of array for given example, then array “a” size will be as follows:
Size of array"a"=(9-0)+1
furthermore, in case of a single-dimensional, the total size of an array in bytes can be computed as:
therefore, what is the meaning of the size of an array? size of the array means the number of elements that array can store base types means and type of elements that array stores such as float, integer, character.
let us understand suppose that if the declaration of an array looks like as following: float a;
furthermore, total memory in a byte that array would occupy will be given by:
size of array=10x(size of float)
therefore, we know that the size of each float variable is four bytes
there are total ten elements in the array, hence total memory array “a” occupies will be 40 bytes.
One-Dimensional array is a Part of array
Implementataion of one-dimensional Array in Memory
therefore, the Address of a particular element in a one-dimensional array is given by the relation address of element a
B = The Base address of an array
w = The size of each element of an array
J = The number of required element in the array
let the base address of the first element of the array is 4000 (i.e. base address B= 4000) and each element of the array occupies four bytes in the memory, then address of the seventh element of a one-dimensional array “a” will be given as: