C++ arrays:
I am giving you the intro of an array. An array lets you declare and work with a collection of values of the same type. Let’s say you want to declare four integers.You would do something like this: int a , b , c , d; What if you wanted to declare a thousand variables? That will take you a long time to type. This is where arrays come in handy. An easier way is to declare an array of four integers, like this: int a[4]; The four separate integers inside this array are accessed by an index. Each element can be accessed, by using square brackets, with the element number inside. All arrays start at element zero and will go to n-1. (In this case from 0 to 3.)
Note:
The index number, which represents the number of elements the array is going to hold, must be a constant value. Because arrays are build out of non-dynamic memory blocks. we will explain arrays with a variable length, which uses dynamic memory. So if we want to fill each element you get something like this:
int a[4];
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
No comments:
Post a Comment