 Hello friends, I am Sanjay Gupta. Welcome back on Sanjay Gupta Tech School. तो आप देख हैं, see language video series in Hindi. और इस वीडियो में जो तोपिक हम दिसकस करेंगे वो है आरे. तो सब से पहले हम देखेंगे की आरे की रिक्वार में क्या है, दैन उसके ताइज क्या क्या होता है, तो आपको लूप के बारे में सारी चीजे पहले से पता हो ना जोरी है, कि बिना लूप के आप आरे निपलमेंट नहीं कर सकते हैं. तो ये सारी मेरी दीटेल्स हैं, e-mail, whatsapp number. तो अगर आप ऊनलें ख्लासर लेना चाते हो, तो आप मुझे ख़्टेक कर सकते हैं, कोई भी डौवड दिस्कुष करना चाते हो, तो मुझे खंटेक कर सकते हैं, कि नोर्बिली योटाए की लीएग डो देगने देखने थे, बोगर सरे डौवड स मन में रहा जाते हैं, तो वो आप मुझे दिसकृष कर सकते हैं, आप जो students, तुब सब से पहले हम दिसकस करेंगे की आरे बेसेखली होताक है, तो शुरुके पास से साथ मिनेट में खिलिटिकल अपको बताँवा, और उसके बाद फिर हम जोभी दिसकशन करेंगे वो सब प्रक्तिकल अड्यंटेड होगा, तो वो आपके लिए लिए लिए लिए लिए � नाए हम रही, अब के अप कषक कर लिए, तो अपका रही से पैर में में, अपके लिए लीए लेए तब खुगे पान करी, अपके बभी दिसकस कर से पास, तो अपकि अपक कषक लिए रही होगा, नदु भाँर बाबद पास से चीऎप गुिशक है, भी बापक कुए दचन यह तब उसंग तब एक दे रब मगराने ऱ करतेंट. यह यह चान तब टग बाज है. अप आप इस ऱाग है. नद बाज वऱद कराई, दे आप चो फ़रन ल्जाता, है तो दे शालग ऱी, दश्वार के नहीं दे साटॉग. आब आप प्रशवाह जाँगे अप प्रशेन चफ़ेगा आप आप अईब आडवाथ आप अगब, ॐंईद of ॐरे ओग अगभ अगभ आप आप गभईईखात आप आप आप यहूँटग में अप आप प्रशेँ प्शाद को में वैसाशाह तो सवर अप प्रशीष कर स if we store more than one value in a variable then it only stores the last value that is one variable can store one value at a particular time so now let's see it practically so I have included a header file and main and in it I have declared a variable now if I assign 5 in A then it will print 5 if I have written A equals to 10 then what happened? I have stored two values at a particular time in this variable in this variable I have stored two values at a particular time so what happened? first it will store 5 then it will store 10 so when we are storing 10 in A then will 5 be available or will it be overrided? so you would say it will be overrided so what is the conclusion from this? that one variable can only hold one value at a particular time so the first point is the same if we store more than one value in a variable then it only stores the last value that is one variable can store one value at a particular time now let's talk about the second point so the second point is that we can store more than one value into more than one variable at same time so the second point is that if you want to store a lot of values then you have to make that many variables so A equals to 5 and B equals to 10 so at one time 5 is stored and 10 is stored so it is absolutely correct that when you want to store a lot of values then you have to make a lot of variables but now what will be the problem? imagine that I want to store 100 values there are 100 students in one class and I want to store the marks of those 100 students or making 100 variables will be an easy approach you will not say it because you will take a lot of time to declare a variable then you will have to assign a value and use it in printf so you will have to type a different name of each variable so to resolve this problem if we want to store a lot of values then we don't have to make a lot of variables so we will focus on the third point but in case of array we can store more than one value in a single variable at the same time and this is what we saw in the third point all elements of array store under a single variable so now what will array do? it will provide you with a facility that you can store a lot of values under the same variable so how it can be done? so what will we do for that? we will declare like this so this is array declaration this is array declaration and here the name of array can be any name the names of the variable you used to use will be applied for the array name but this variable we have declared in the form of array its specialty is store 100 integers under the same time and the 100 integers will be accessible through A variable okay now let's move ahead first let's take a type there are three types available 1D array, 2D array, 3D array so in this video I will tell you about 1D array and in the upcoming videos you will learn about 2D and 3D so 1D array basically what it says collection of more than one elements so 1D array basically is one dimensional it will be one row in which you can store a lot of values then 2D array is collection of more than one 1D arrays so here basically like in mathematics you make matrix so what you do is you create a collection of rows and columns so how you can create the same collection in 2D array so when we have to make a lot of 1D arrays then we can convert it collectively to 2D array and same with 3D array it is collection of more than one 2D array okay so when we will discuss 2D, 3D in detail then you will understand but in this video you will understand 1D array properly so let's move ahead now 1D array declaration so I have already told you first we have to use data type then we will use the name of array and in square bracket what you have to mention is size so you can see three examples first, second and third so first integer array is made whose size is 10 then float array is made whose size is 10 then character array is made whose size is also 10 variables name is different and data type is different size can also be different it is not necessary that every array size is 10 size will depend on how many values you have stored okay now how much memory will be allocated it will depend on which data type so if you have 16 bit compiler then in integer there are 20 bytes if you have 32 bit compiler then in integer there are 40 bytes this is only difference in int if you use any compiler in float then if you have to store 10 value then every block will get 40 bytes and in character one block gets 1 byte so now if we are making 10 block then how many bytes will we get? 10 bytes so you can read the note below we can declare any type of array so you can create any type of array okay now this is memory allocation so for example if I declare an array int a of 10 so what will be the name of array? a this is name of array through which this whole memory will be represented so the name of this whole memory is a every block's name will be a total number of blocks will be 10 so now you will say that every block's name is a so how will we identify them uniquely so for that we use index so first block's index is 0 second block's index is 1 then 2, 3, 4 up to size minus 1 so if the size of array is 10 so last index will be 9 so it is written below index is used to access location of an array uniquely so how will we write its examples so if I want to store a value on last location then what I have written a of 9 equals to 50 so 50 will be stored on 9th index so this location will be stored and your value of 50 will be stored so now you will understand how we will access the individual location of an array you have to use the name of an array so what we will write between the square packet is index so it is written in the comment assign 50 at 9th index of array so if you want to assign on any other index then you will mention that index now you will say that we have to write different variables so when you input from the user then you don't have to write indexes again and again we will iterate a loop and that loop will generate different indexes because the name of an array is the same we have to change only index so now I will tell you practically how we will read an array through the same variable and we don't have to write the name and index again and again it will automatically generate then if you want to assign any value of an array in any other variable then look here X is a variable and what we have to assign is the value available on the third index of an array so third index means this location so on this location the value available on this location will be assigned in X variable so you already know that on the right hand side it always assigns its value to the left hand side so you can read the comment assign value of third index of array into X so in this way you will understand how to declare an array memory is allocated in this way so you will understand that and how the actual implementation of memory is is explained what is the index it tells you that we will use index to access different locations so the name of an array will remain the same and for individual locations we use individual indexes now let's talk about initialization if we want to assign any value in an array then how we will do it so initialization means assignment of values at the time of variable creation so if we look at a small example if I write int a equals to 50 so this statement is known as initialization that I made a variable a and assigned it 50 so what we are discussing here that if you make an array then how you will initialize values so there are 3 statements valid so first is int a5 equals to 1,2,3,4,5 so now you have to use curly basis to assign value so size 5 was there so we have stored 5 values if you keep size blank and initialize then this will also be okay but if you keep size blank in this case if you keep size blank and value is not initialized then this statement is not okay this is invalid so if size blank is there it means you have to assign value because the value you will assign you will know the size of the array and in c programming you have to mention the size of the array otherwise you will not know how many memory you have to allocate now this is also invalid that size 2 is there and you have stored more than size so this will also show the error so it is also not okay so size is more and less value will be initialized so this is okay so what will happen here 1st or 2nd index will be assigned and remaining blocks will be assigned so this way you can initialize values in array now let's talk about how to read and print the array so I told you that we will not have to use index again and again we will trade a loop and in the beginning of the video I told you that when you will read the array then you need to be familiar with the loop so I hope those who are watching this video have already read the loop and if those who have not studied the loop and are beginners then in the video description there is a playlist link available on the first number so open the playlist there are 3-4 videos of the loop then you will understand then you will understand the array properly so now how many times we have rotated the loop 10 times it started from 0 to 9 because what is written in the condition i less than 10 so when it will be 10 then it will be false means it will be true till 9 so 10 to 9 means 10 times every time what is written here is a of i so a is fixed the name of the array so first i will be 0 so it will be a0 then i will be plus plus so i value will be 1 so first value will be a0 index then it will be a1 index then it will be a2 index so now you will understand if we want to store data in the bulk then using the array is beneficial because through the same variable we can store many values and we do not have to write the statements again and again we can repeat it through the loop and similar to reading you will not run the loop for printing from 0 to less than 10 till 10 and here we will print a of i so again first it will be a0 index then it will be a1 index and so on so this was the theoretical explanation now we will go on the practical implementation so i will tell you a program by implementing it so that you can understand whatever theory i have explained so let's go to our slide so i told you the need of array what is the requirement the types we have picked so we have covered the declaration memory allocation initialization and how we can read and print it so first i will tell you the practical implementation and then we will implement it so now i have declared array so first i will tell you the initialization values initialize so this is 5 and in this way you can initialize values now i have put values in array so i don't need to take input from user i can run it so i have to get these values displayed in output so first i have written printf array contains so it will be as it is printed after that i have written it will be as equals to 0 i less than 5 i plus plus and with this for loop i have written printf for which will print the elements in array and i have declared the variable so loop will run from 0 to 4 so first it will print the value of a0 index then a1, a2, a3, a4 total 5 values will be printed so i have saved it now let's run it array contains 1, 2, 3, 4, 5 okay now if we go back to our ppt so this initialization you must have understood in the first statement now let's validate if this is valid or not so now let's blank it the size is nothing but i have put 5 values so the size of this will be 5 if i add one more element then loop will have to run one more time so that all the values will be printed on your screen so let's execute the compile 1, 2, 3, 4, 5, 6 the size of the array is decided and it is working properly now let's declare an array b and it doesn't mention the size nor initialize it okay now let's just compile i am not running it there is an error on compilation time storage size of b size of b isn't unknown sorry isn't known so you didn't mention the size of b nor initialize the value so there is an error here when there is no error on the top statement because we initialize the values here okay so this will be invalid so i have justified this so we have run this as well run this as well now there are 2 things left let's run them again if size is 2 and if you initialize the value then what will happen see there is an error again too many initializers for int2 so size is 2 and you have assigned the value so this will be invalid so it means we have tried this as well so as i told you and now let's try that the size is big let's say size is 20 and the value is 6 so now it will run properly so 6 values are displayed there is no error so the things i have told you theoretically as it is working now you must have understood that we can store many values in the same variable so this last point you must have understood but in case of array we can store more than 1 value in single variable at same time so we have to do this so in single variable and in the same time we have to store many values and process them and we have not written printf that we have to print value we are writing 6 printf neither we have used 6 variables instead we have used loop so without loop the survival of array is not possible so first read loop and then read the array so programming is basically a sequence if we miss one topic then you won't understand the next topic so we have already covered this so now the last part is 2 programs if there are many values available in array then how to print their sum and secondly how to print the values available in array so with the help of these programs you will know how to input from the user so first program write calculate sum of values load in array and array is very popular when you will find a job you will complete the data and when you work in industry you have to manage the data in bulk so the array is the most popular data structure so its name can be different so in some places we use it in list form in some places as it is we use it in array form so it depends on the technology so in every technology the term can be changed so in C we call it array means collection so the meaning of array in English is collection so now we will input from the user 10 values and we will print their sum on screen so I have written the size of array 10 so to calculate we have to initialize it from 0 now I am writing printf enter 10 values after that a loop will be iterated which will go 10 times and now with this loop we have to repeat the scanf because we have to input values from the user and you can write a of i so printf enter 10 values on screen this loop will go 10 times so you know how the loop works so when the loop goes 10 times it will start from 0 and go up to 9 so first value will be stored in a0 then i will be 1 so next value will be stored in a1 so you can see the name of array will always remain the same index will automatically change so whatever value we input it will go to different index and it will be stored okay now we have to calculate sum so I am iterating another loop so i equals to 0 i less than 10 and i++ and in this loop we will write s equals to s plus a of i so whenever you have to process the array you have to keep in mind that to patch the index the loop counter variable you can use it if you have written j or k you can use it too so in the s variable whatever values are available it will be added after the loop is finished you have to print the sum so you can write sum equals to 0 i less than okay now tell me will this printf repeat with the loop so your answer should be no because with this for loop and when it is not based on loop it only repeats one statement and to print the sum do we need to repeat the printf you will say no because if sum is a single value we can print it through a single printf for that we don't need to use the loop so let's run this so I will enter 10 times 1 so we can validate our output so sum equals to 10 so we can validate our output sum equals to 10 so it means our program is working properly now you want me to display the array along with the sum then you can do 2-3 things what you can do first is to calculate the sum for this you can write it here so you can cut it from here put the curly braces here and paste it here paste it here and cut the scanf from here paste it here so this is also possible so what will happen with this now this for loop will read the value so scanf will store value a of i on the position and it will be added in the S variable so 10 values are read and their addition is stored in the S variable when this loop will end then printf will display the value of S on the screen now you want me to display the input in the array those values are also displayed on the screen so for that you can write a printf array contains and then implement a loop and then put printf in this loop and this will display the values of array on the screen so again this loop will repeat the same printf there is no curly basis with the loop and when all the elements will be printed then this single printf will display the sum so let's execute this again so now I will enter all the values so look array contains all the 2 prints are 10 times and sum print is 20 so if you have a requirement to display the array and in the calculation you can do that you can see how we maintained many values through the same variable now you will say that this is working for 10 if we have to process 20-30 values then there is no problem you can do the size of the array and whatever loop you have written run it for 20 times so now it will work for 20 values so look how easy it is if I say to make 10 variables then you can read them and print them as soon as I say to declare 20 variables then you can change this program as soon as possible you can say no because we take so much time to make 20 variables so I have changed the program by modifying the size so the array becomes very beneficial when you process the data in the bulk so now if we execute this program so now I will enter 4 so you will see that I will enter these values for 20 times so I will do this 5, 6, 7, 8, 9, 10 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 20 values are printed so the input I have made is above after that the array contains 20 values and after that 20-4, 80 so in this way you can easily modify the size of the array so I hope you have understood how we process the array now let's see the last program print array values and reverse order okay so print array values and reverse order so I will tell you both that in the order in which we have printed the input of the value user and also printed the reverse order so let's take size 10 now we don't need some variable here also size 10 okay let's remove this base because we don't want to make some we want to repeat the same statement okay now array contains so this will be printed okay I will copy this and paste it again and here it is written array reverse okay from here we have taken backslash and removed it so what will happen to it after every digit it will be comma printed and here we will paste slash and from which cursor will shift to new line here also we will paste slash and from here we will paste slash and after percent D so after every digit it will be comma printed so now see both the loops are going from 0 to 10 so this is the order in which you will input will be printed in that order we have to print the reverse too so what we have to do is start from 9 and run the loop greater than equals to 0 and minus minus okay I will tell you one more way of this so first let's see that we have started loop from last so we know that size 10 is above array so what will be the last index size minus 1 means 9 so we have started from 9 so what will be the first value which will be printed so it will print a of 8 then 7 and where it will go till the time the value is 0 as soon as it will be minus 1 then it will be terminated so let's execute this so see 1,2,3,4,5,6,7,8,9,10 so now see array contains first we are printing in increasing order and second array is printing reverse in which 10,9,8,7,6,5,4,3,2,1 okay now you will say now you will say that I have to run the loop in this way I don't want to change I have to run the loop from 0 to 10 and still it will be reverse printed so there is no problem so what will you do for that so you can perform the calculation here finally the result should be an index value so see i is initially 0 so what will be this 9 minus 0 means 9th index will be printed then i will be plus plus and 1 will be 1 here i will be 1 so next time what will it be 9 minus 1 means 8 then i will be 2 so 9 minus 2 means 7 so when we will run it again you will see your values will be printed in reverse order so this is the second way to process the elements of array so in the first output input is coming in the same form and second array reverse will be in reverse order but the array reverse will be in reverse order so i have told you two ways to process the array so how to do that so in this way we completed the basic of array so first we covered the theoretical part and after that i have told you these two programs and the theory i have told you the practical implementation so i hope you have understood all this no doubt please communicate with me so that i can solve your problem and don't forget to watch the next video because in lecture number 16 i have listed many programs related to 1d array which are listed in front i will tell you by implementing them so we will discuss all the programs one by one i will implement them and i will try to explain and after that the next video will be about 2d array and 3d array so follow the whole video series so that you can learn more about programming so i hope you have enjoyed the sea language video series which you are following if you have any problem please communicate with me and share it with your friends so that you can read the sea language properly if you are a beginner so thank you for watching this video