Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Monday, August 31, 2020

Arrays

 


Well most of you may be familiar with the word array if not then you will be after reading next few lines.


What is array?


An array is a variable which stores number of values with the same data type. Where data type is kind of sense of computer through which computer recognize the type of data. Array is initialize by the square brackets []. Numbers of brackets shows the number of dimensions of an array. Single set [] of square brackets shows the one-D array. Where the two sets [][] of square brackets shows the 2-D arrays and three sets [][][] of square brackets shows 3-D array and so on.


When you need to store values with same data type then you need to initialize an array with same data type of values. Suppose we have numbers of integer values. Than you need to initialize an array with int data type. The int data type is also a variable just like array which is predefined in the standard libraries. Int stands for integer.


Initializing an array without its size will generate an error!


Defining size of an error is important if you do not define or set array size than null-pointer-array error will be occur. Where in c++ we have only arraying concept but in JAVA we have array list concept. In array list, You just need to create and object of an array list and you do not need to set size of array list because array list is flexible component in java which size can contact and expand according to your need. You just need to add value in array list by add keyword. Anyways array list is another topic lets just come back to our arrays’ topic.


Errors :


Some errors can occur when we are using arrays.


i- Size of array


If you forget to put the size of an array then error will be generated.


ii- Wrong data types


If you try to add different data type values than array data. e.g : Array data type is integer and you are trying to store character( CHAR) data type value then error will be generated.


iii- Wrong index


There may be so many logical errors due to wrong index such errors compiler will not show. Arrays index starts with 0 and than 1 and so on. it means you store a value without referencing index than it will store in index 0 than if you want to store an other value without referencing index than next value will store in 0 index and you previous store value will be removed.