Category
📚
LearningTranscript
00:00Hello everyone, this is Sandeep. Today I'm going to cover one of the important topic
00:08that is array. Before array we have covered loop, we have covered if statement and in
00:18those programs we have used local variables. If I have to create one of the program and
00:27that program is this. One of the easy program is to input salary of three employees from
00:40keyboard and to display it on screen. Suppose this is the program so you will say that it
00:52is very easy program. We have to take three variables and then we have to use scanf to
00:59input the salary of three employees and then we have to use the printf to display the salary of
01:06three employees. Obviously we have to do this but suppose if I make some changes in this program
01:13and in spite of three employees if I have to input the salary of 100 employees from the keyboard
01:21and then I have to display the salary of 100 employees on the screen then naturally
01:30the length of the program will increase as I have to take 100 local variables and then in
01:36100 local variables I have to store the value. With the help of scanf I have to read the values
01:43and store inside the variable and then I have to use printf to display the salary of 100 employees.
01:51So the length of the program will increase the program will become lengthy and suppose if I
02:00include that display salary of employees in sorted order. In a numerical sorting you have to do you
02:15have to display it in a sorted order. As the values are inside the local variables and the
02:22program is lengthy and then you have to arrange them in a sorted order now it's become more
02:29complex. So these are the different difficulties which the programmer faced
02:37and because of this what the C developer did they came up with a new variable they came up with a
02:45new concept and that new variable is known as what array. So array is a variable which can store
02:55more than one values of similar data type or you can say array is a variable
03:03which can store more than one elements of similar data type.
03:09So in a local variable we can only store a single value but in array variable we can store more than
03:20one values. So I have explained both the things why array is required and what is array.
03:34I have given both the reasons I have explained both the reasons.
03:40So if you have to understand or if you have to define you can say
03:50group of related elements having common name that is known as array. In C declaration of variable
03:59like this data type and salary and the size is here inside it that is 10. So this array variable
04:09can able to hold salary of 10 employees okay and the data type of it is what int. So only the
04:18integer values are going to store inside it okay above syntax declares array name salary which can
04:27store 10 elements or we can say that the salary of 10 employees can be stored.
04:35Once you declare once you write down if I take this example int salary 5, the five locations
04:43are going to create inside the memory inside the random access memory at run time okay
04:50for the five employees for the five employees salary okay. In array the counting always starts
04:58from zero, zeroth position and this is the first position, this is the second, this is the third
05:05and this is the fourth. So the salary of the first employee is going to reside inside this
05:13zeroth position, the salary of the second employee is going to reside inside the first position of
05:19an array, the salary of the third employee is going to store in the second position of an array
05:25in the same way the salary of the fourth employee is going to reside in the third
05:30and of it in the fourth position okay. So the counting always starts from zero so from zero to
05:37fourth it will be what zero one two three four that is total what five okay. So the
05:43you can say in this way the values can be stored okay and then we can be able to
05:52display or whatever task is given we can able to perform it.
05:58To store the values inside this locations of an array on the zeroth, on the first,
06:05on the second, on the third, on the fourth we have to use loop. In array we have to use loop
06:12and then only we will be able to store the values inside these memory spaces of an array okay.
06:20In the next video I am going to explain a simple program that how to store the values
06:27okay in an array which can store only similar data type values and then how we can able to
06:33display those values or you can say the elements on the screen. Thanks for today.