 Hello friends. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I am going to compare array and string. So I will be explaining what are the similarities and differences between array and string that are used in C language. Before starting, I just want to share our information. If you go to detail or description of this video, you will see links of various playlists related to C language. So you can watch that too. Now, coming on to the topic. So if I talk about array first, so basically the meaning of array word is collection. Meaning of array word is collection. So it holds values collectively under a single variable. So if I write this. So it means we declared an array whose name is A, it will store 10 elements of integer time. So it means to store all integers collectively, you can declare an array. So this variable will be treated as array in this case. Now in C programming, we can declare an array of any data time which are available to use. So here you can see three declarations are available in flow and care. So ABC, these three are arrays of different types and they will be storing different quantity of data. So this is about array. Now coming on to string. So in case of string, we only use a data type that is care. And let's say this way I declared string. So string is nothing. It is basically an array string is basically an array because you can see the statement is available here. And I have mentioned this here as well. Right. So this can be used in both the ways in terms of array and in terms of string. So now you might be thinking how we will identify like this is character array or this is a string. So you need to know this treatment. So here I'm writing a string is collection of characters terminated by this null character terminated by null character. So it is known as null character. Right. So this way you can identify like if your character array is not having null character at the end, then it will be known as character array only. But if your character array is having a batch slash zero or null character at the end, then it will be treated as string. So this is the basic difference between array and string. So arrays don't contain any null character, whereas string contains null character at the end. Right. And in case of string, we can use only character data type, but in case of array, we can use any particular data type. Now you might be thinking like explain more about the character why in case of string null is required, but why in case of array null is not required. Right. So now I'm going to explain this. So I'm going to take an example of this. So here you can see this is in these are added whose size is five and I'm removing this and let's say here I'm writing str of five. Right. So right now both are arrays. Right now both are arrays. This is in these are a and this is character. But we are assuming that it will be containing null character at the end. So it will be considered as string. So in this case, we are in A of five. So this array can store five different elements at different indexes. So let's say this is memory location and here we have these five indexes of this area. Right. So now let's understand how we will put five different values into this array. So if I provide five different values like this 11, 12, 13, 14, 15 all together. So as per you, these are five different values, but you're putting that all together and you're pressing enter. So what will happen? They are five different values. They will be considered as five different values or one value. So in case of numerical terms, it will be considered as a single value. Right. So this single value will be stored in zero context. So you are providing five different values, but it is considered as one value. So this will not be a valid input in case of this. So what you will do, this is invalid. What you will do, you will provide input like this 11, then enter 12 enter 13 enter 14 enter and then 15 enter. So this way you need to provide values so that five different values will be stored at five different locations. Right. So whenever we are working on numbers or we want to provide separate value for separate indexes, then we need to use this approach and to read these values from user. You can apply this group because we require five different values. So scanners should repeat five times. We require five different values. So scanners should repeat five times. And with this logic, you will be providing these five values and they will be stored like this. So this is the overall process of idea. We didn't pick this notation. This is incorrect. And this one is correct. So knowingly, we need to provide each element separately by pressing and right. Now I'm coming to this. Right. So string is so before telling it string, let's consider is a consider it as character. Right. So I'm going to read values for character. So let's say I'm going to input any name. So I'm increasing its size to 10. Right. And let's say I'm going to input my name. So here also we have one scenario. So again, you can compare this in case of integer. I provided 11, 12, 13, 14, 15 all together. So it was considered as a single input that was wrong because it will go to this location only first location. So we divided it into five different ways by pressing and. Now here in case of character, which input will be valid this or this, how you will enter your name by pressing enter the after each letter or by typing whole name and pressing and the key points. So I think this will be valid and this will be invalid. Right. So in case of character, knowingly, we want to type all the characters all together and we want to press enter. So that this will become a single input. And here we divided this input into five inputs. Right. So to read this input as a whole, we don't require any loop. We just use this. Or we can use a single scanner having percent as and str. Right. So get us or percent as they are internally capable to store all these elements and different locations. So here automatically name will be stored like this. Because of gathers or percent as. Right. So they are particularly built for character. Right. So they will receive this as one input and it will be internally and will be stored at different locations. Right. So now I hope you understood one major difference of how we can be. Arrays and how we can be character that is that will be known as string. So right now I explain you a working off character at it, but you can't say it as a string until you insert null character. So here you can see total 10 blocks are available. Right. And let's say I'm putting here 50. So here sizes 50 and you are repeating you five times. So then you will be executing your program. So you will know how much data you are providing as input because you are creating it to a loop. So you will know five values are provided by the user so you can process those five times. But here in this case we are not rotating any loop. We are just reading input through gathers or scanner. So if my name is having six alphabets, so six locations will be occupied. If in your name, let's say eight characters are available for it will occupy eight locations. So here input is not having fixed length. So how we can identify where our input is terminating or where our input is having last value. So for that purpose, that is, or this person has automatically inserts null character at the end of it so that we can identify how many characters are entered by the user. So we need to search for this null character where this null is available before that all the characters are entered by the user. So this is the reason why we read a character areas as a single input because we cannot split all the characters individually. And knowingly we want to provide input together as a collective input, one input. And we need null characters so that we can identify the last position because we don't know how many characters will be entered by the user at runtime. So I hope this way you understood the difference between areas and string. So string has only two special characteristics. One is the input nature that is reading all the characters and all together and the whole one input. And at the end, it will be having null characters so that we can identify how many characters are entered by the user. And in case of array, always we are going to repeat or iterate a loop. So we will be knowing how many numbers or how many elements will be provided. So we don't require any null characters because we know actual quantity that is entered by the user. So this way I hope you understood the difference between array and string and the similarities. So somewhere they are similar and somewhere they are having different working nature. So use array and string as per your requirement. So if you are working with name, address and you want to read some information related to characters that are having alphabets, digits and special symbols. So then you can prefer string in form of character array. But if you are using digits only, so you can declare int or float arrays. So in that case, you can prefer this. And so I hope you understood whatever I explained in this video. If you want to watch more programming related videos, open my channel, go to playlist. So there you will be having various variety of videos. And you can also go to detail or description of this video where you will find links of various playlists related to C language. So you can boss time too. Thank you for watching this video.