 Hello everyone, in this video I will tell you about array. This topic is included in the BCA and MSCIT program. Here I shall discuss first about what is array, why array is needed in any programming language, then initialization and declaration of array, different types of array and all. First, I will show you the theory part by using a smart board and then I will show you the practical part in my laptop. So, the learners are requested to be prepared by installing the Turbo C++ in their laptop or desktop because the simply listening the lecture is not sufficient, you have to practice at the same time. So, now the topic is divided into four sections, they are the introduction of array, then initialization and declaration of array, then in the second part we will discuss the types of array that is one dimensional and two dimensional or multi dimensional array. So, first let us see the objectives of this chapter, the four objectives are there, one is after this unit you will be able to know the what is array. So, first one is this and the second one you will be able to declare and initialize an array, then we shall discuss how to create and access a one dimensional and two dimensional or multi dimensional array. Then let us see what is array. So, first array is a collection of similar data types. I think everybody know about the basic data types which are used in the programming language. Actually basically there are four data types, one is integer data type, character, floating point and other one is the double. So, these are the four data types and for this array, array is a collection of similar data types. That means, in an array we cannot store one integer, one floating point, one character like this. If we create an array, it can store only the integers data type or if the array is a character, it can store the character data types like that. So, next one is the what is it can the array can be defined as a finite order and collection of homogeneous elements. So, first is what is finite? Finite means the array can store a fixed number of elements that is finite. It cannot suppose an array cannot store an infinite number of elements, it is the number the size of the array is fixed. Next is order. Order means the elements are stored in the array in a contiguous memory locations. That means, in computer memory arrays are the elements of the array stored in the linear way. In the memory we cannot store the array in a scattered form. So, it is called the ordered collection or it is in the ordered way, elements are stored in the ordered way. And next is the homogeneous elements. Homogeneous means the same data items, same types that is if it is integer all the elements should be integer that are stored in a contiguous memory locations. Next it is a group of contiguous memory locations that have the same name and type. That means, the if the array is variables the name of the variable is same for all the elements in the array. So, next is the type of data items in an array may be character, integer or float. And the elements of the array share the same variable name. So, if we can say that the creator array of the variable name suppose integer array variable name A. So, if array is defined like this we shall discuss later. So, all the elements in the array are use this variable name A. So, elements of the array share the same variable name. So, all the elements in the array use this variable name A. Then let us check one example of the array. Suppose A is an integer array that means it stores the integer data types and it contains 10 elements. So, how we define array? It is A0 up to A9. One thing it is important to remember here that our array always starts with our position 0. That means it is starts the first position of the array is always starts from 0. So, if it is contains 10 elements then how many the positions will be from 0 to 9. And the elements of the array A referred by giving the name of the array followed by the position number. Position means one position the element is there. Suppose array this is the array it elements are stored here. So, how many elements it contains 10 elements? So, like this here. So, first position so, this position is A0 and next one is the A1. So, like that it goes here. So, first the elements of the array A is referred by a given name of the array followed by the position. So, this 0 is the position which position the first element this is the first element. So, 0 is means the first position of the array. Suppose in the first position it contains the number 2 the element is true it is in the first position where it in the array name A clear. Then the first element in every array is the 0th element already discussed always the first position is A0. Then the elements of the array A is referred as a second element is A1. And if total number of elements is 10. So, the last position will be 9 that means the ith element of array is referred as a A I minus 1. So, I may be any one maximum number of elements that contains in the array that is the I and the position number in the square bracket. The position we always symbolize as a square bracket and that number is known as the index or subscript and the index is always a integer. We cannot given a float number floating point number I think you everybody know what the difference between floating point and integer. So, integer means the number which does not have the decimal point that is the integer and floating point means the number which consists the decimal point. So, the index that means the position of the element cannot be a floating point or character or else it must be a integer or a integer expression. Next we shall discuss some terminologies which is associated with the array. So, first terminology is the size. Size is the number of elements how many numbers are there in an array that is called the size. And next is the type already we have discussed what type of data are stored in the array that is the type it may be integer it may be character floating like that. And next important thing is one is base what is base? So, base is the address of the first element in an array and next is the index. Index is an integer value which gives the position of an element of an array. So, position of the element in an array and ai it is denoted as ai where a is the name of the array and i is the subscript or index. Then since array element are identified by using an index. So, array is also called a index or subscripted variable. And let us check one example it will be easier for you if you see this example. Suppose this is an array of name a. So, a is the name of the array and subscript is the this one is the index or subscript. And the address first memory locations that means when we define an array then what happened it stores some space in the computer memory. So, here the first address in the computer memory is specified as 600 clear. So, next element is stored in the 602 here I want to tell you that the integer type data for short integer type data it takes the occupy the size as 2 bytes. I think previously everybody learned this one that is integer type data the size of the integer type is integer type is a 2 bytes 2 bytes for short integer or it may be 4 bytes. 4 bytes means for if the compiler is a 60 32 bits then the size of the integer type data will be 4 bytes. Then float data is a 4 bytes then character data types is a 1 byte so and double double data types means when the numeric value is a very long means large values are there it may be a floating point or integer type. So, double data type say size is the 8 byte. So, these are the size of integers different data types. So, here since the this is a integer type so it stores 2 bytes. So, here 600 next address of the next element will be 602 then again next is 604 so like that. And the last address of the last element is 618 and these are the elements what are the elements here first element is 10 second element is 12 like that and the last element is 89 so these are the element. So, here in the introduction of the area what we have discussed first we came to know that what is array. Array is the collection of similar data type next we came to know the some terminologies associate with the array. So, first we learned that the type of the array size of the array index and base now array declaration and initialization. So, when we declare the array declaration can be done in various ways and usually we declare an array or initialize an array in the beginning of the program. So, how we declare an array? We for to declare an array first we have to specify the data types means the what type of data are stored in that array. Next we have to specify the name of the array that means the variable name the variable is array type variable and what is the name of the variable. And then we have to specify the size of the array which is have to specify inside the square bracket. Then what is the syntax first is a array data type it may integer character float like that and then the name of the array then the size of the array and the size is within the square bracket. So, let us check one example to declare an array by specifying size in the declaration. Then how we write the steps first is integer data types then array variable and then the size means it is the five size means maximum five elements can be stored. And then if it is a character array so character c h a r we have to write c h a r then array and the size. Size is 10 and next another declaration way which is specify user defined size that means we can specify the size in the runtime in the runtime of the program. So, first we specify we initialize an variable that is called size. So, size is a variable which is integer type and we have defined as a 20 20 is the value of the size. Then here next we write the integer array size means array is the variable name and size means it takes the value 20. So, these are the steps different way to declare an array. Next another way an array without allocating the yes if we are not specify the size of an array then what happen some garbage value it takes some garbage value in the size data then there may be some error in the program. So, we have to specify the size of the array in a program. Next we shall discuss why we need an array. First suppose if we have some small variables suppose 3 variables then we can define that the 3 variables suppose variable a b or c. Suppose we have in desired suppose variable n 1 we can define it is an array of size 5 then in desired n 2 this is one array of 10 size or in desired n 3 so this is one array. Now if we have more variables suppose 50 100 if we have more variables then how we can define we have to write 50 times in desired n 1 in desired n 2 in desired n 3 like that. So, it is not possible so in that case we can use the array. Let us see one example why we need an array. Suppose there is a cricket match has been organized between two teams a and b and we need to record the scores of team a. So, how many players there are 11 players. So, we can in desired score suppose variable name is bet and the scores are score 1. So, this variable stores the run of the first cricket player. Then we can define up to 10 numbers of players. So, we can write in desired bets score 2 3 4 up to 11 players so 11 variables. So, it is very easy, but if we want to store the variables that is run of the whole match suppose there are three teams. So, for three teams we have to store the runs for all the team members. So, how many variables are required 33 variables are required. So, in that case we have to use an array how we use suppose team a, team b and team c these are the three variables and we give the size as 11. So, 11 players so we can define is the as a array. So, to define a large number of data the large number of variables we use the array. Next array initialization how we initialize an array. Initialization processes generally what is initialization we assign the values in the array. Then initialization we give similar to the declaration we give first the data types then variable name array name of the array and then the size. And one more thing we have to give in the initialization that is the values of the data elements which is within a braces this curly brackets is used. So, the syntax is the integer that is data type then variable name my array this is the name of the array variable then size, size is inside a square bracket then other the elements we have defined suppose size is 5. So, 5 values are there. So, this is the statement to initialize an array this is a integer type a is a variable 5 is the size then what are the 5 0 sorry 1 2 3 4 5 that means what in position a 0 the first position already you have discussed the first position is specified as a 0. So, a 0 contains the value 1 a 1 second position value is 2. So, like that the last one is the fourth position value is the 5. So, this is about array initialization yes here we have given here there are 5 elements in size is 5. So, the positions and the values elements of the array. And an array can be also initialized by using a loop. So, loop they are generally used three loops one is for loop, do and file these are the loops are used this is an example of for loop. So, how we write first we declare an array that is integer array size is 5. a r r is the variable name then for loop is what for i equal to i is a how do we use the for loop suppose i is a integer variable. So, integer i i equal to 0 means first initial value is i is 0 then maximum size is 5. So, i less than 5 i i plus plus first array that means i is 0. So, array 0 is what 2 into i that means 2 into i is 0. So, what is the value it is 0 first then again it checks it transfers i plus plus that means next value is 1. So, second case array next value is 1. So, 2 into 1 equal to 2. So, first is 0 then it stores the 2. So, like that plus plus means up to it will check the array is next value of array is 2 it is less than 5. So, again a 2 equal to 2 into 2. So, the third value is 4 like that. So, what are the values ultimately array contains 0, 2, 4, 6 and 8 next how process processing with an array. So, now here what is there this integer type array it contains the 5 values 10, 20, 30, 37 and 40. So, we have defined the arrays are stored like that way accept these values what function is used it is scan f function is used. You remember the scan f function is used to accept the values in an array and it is statement is written as this is percentage d. d is used for the integer type variables and for c is used for the character and string is used for s like that as it will be different depends on the type of the means what type of elements are stored in the array. Then ampersand a 0 this is the symbol it is used in the scan f function and by this statement we can take the value we can accept the first value that means a 0, a 0 value it takes the values and another function it is a printf printf means it is used to print means give the value in the output by using the printf statement we get the value. So, this statement will be printed the value of the first element. So, a 0 and for character type we have to used s s or c means character type means the variable may be a a 2 j 0 to 9 like that and only in one character is stored in one position in the array. Next a a string is a what is a string string is a collection of characters means more than one characters and which are treated as a single data items and at the end of the string we have to use a this symbol that means null it is specified as a null character. Suppose character we gave an example India is great. So, here we have not defined the size in the above declaration it is a dynamically a dynamic allocation of the array which is name is s and this first is i i is a single character it is stored in the s 0 position then s 1 n India and there is a blank that is s 5 is a blank because there is another word is there. So, is these are the positions of the array this s 14 should be here that is a null character. So, this is the declaration for the character type array. So, in this video what we have understood that the how we declare and initialize an array. We use generally scanf to accept the values in the program and printf statement is used to give the output means to print the value in the element. The next we shall discuss the one-dimensional array.