Array In Rust Programming

                                                                    


 As we are acquainted with variables in Rust programming. We are not able to write a program that handles a lot of data using only simple variables.
    So, we need a mechanism that solves this problem. We can declare an array that can store a lot of data with a single variable. An array is a special type of variable that has several compartments like a room in a hotel and each data is stored in a single compartment, and each compartment is numbered like a room in the hotel. The numbering of a hotel room starts with 1 but the numbering of an array compartment starts with 0. So, the last compartment number is one less than the length of the array.
    We write data between [ and ] and separate with commas to be stored in an array. The most important point is that an array can store only a single type of data i.e. all data stored in an array is of the same type.
    To declare an array two pieces of information are required, firstly, the type of the data and secondly the length of the array i.e. how many compartments will be in the array.  

                                                                           
    To access a compartment of an array we use the compartment number (it is known as the index) between [ and ] after the array name e.g. myarr[0] is the first element of the array.



Happy reading. Keep in touch.

Comments

Popular posts from this blog

Programming Concepts Part I

Rust Hello World Program

Programming Concepts Part II