Skip to main content

Array In C++ (Basic Level)

Just think, one day your teacher give you a box of different types chocolate, and tell you there are 10 types of chocolate you count only how much each type of chocolate , and put those numbers in your program and determine sum of them.
What you will do? You able to count all chocolate number and store them in different variable. At least  10 variable need to store them. Do you know you can store them  into one variable? The method of this name is array.
Array is the method of store one kinds of data into one variable.

5
7
5
2
9
8
11
4
3
10
      0             1              2            3             4            5              6           7             8             9

Here are ten boxes which contain ten same type of data.  We give number of those box for specification their position . so 0 no index contain 5, 1 no index contain 7……..

If we write them as chocolate[0]=5,  chocolate[1]=7,  chocolate[2]=5,  chocolate[3]=2,… …  . .    so chocolate variable store all of those item, its called array.

An array is the collection of one kinds of data. In  a array we can store one type of data. An integer type array we can store integer type data , an character type array we can store character type of data.
For use an array first need to initialize an array with length. Length is the capacity of array. How much data can store an array its called the  capacity of the array.

Int chocolate[10];

Here int is the data type of chocolate array and 10 is the capacity of this array.
chocolate [0]=5,  chocolate[1]=7,  chocolate[2]=5,  chocolate[3]=2,… …  . .
when we use array the position of array length we use index number of array. here 0,1,2,3... are index number.index number of array start from 0.

observe the code 




 Please read the next for more about array.....

Popular posts from this blog

Input & Output In C++ (Basic)

Cout<<”Print sentence”;     This statement is use to print out any kinds of sentence or string type values. Cout<<345;     This statement is use to print out any kinds of numeric numbers, without change. Cout<<variable;        This statement is use to print the value of variable. The value of the which variable we want to print, It is need to write that variable on variable place.

Switch, Case, Default Statements In C++

Switch case is uses as alternative of if….else. When we need to use long term of if…else then we use switch case for reducing program execution time. syntax: Switch(variable){ Case value 1: Statement; Break; Case value 2: Statement; Break;

do...while loop in C++

The do while loop is very similar to while loop . In the while loop first check final condition then execute the statement. But in the do while loop first execute the statement then check the final condition. Syntax: Initialization; Do{ increment/decrement;   } while(Final condition)