C_46 Arrays in C - part 1 | Introduction to Arrays

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the series of learning programming and c i'm going to start a new concept and see that is arrays in c right we will discuss everything about array first of all what is needle fairing what is area the proper definition declaration of array types of initialization of a different type of operations that you can perform on arrays in c right but all the things i'm going to discuss in detail with my new details so that would mean separate videos in this video i am going to tell you the basics like what is needle fairing right why why you use array in c and array any programming language not in c c c plus plus and any programming language java or python anything right what is nero ferry then we will see proper definition of array and then we will see what declaration of error right and first of all i'll uh i'll you know teach you on this whiteboard the logic i'll tell you whatever thing the theory part and then i'll show you this concept means practical of arrays how areas can be declared what error you will get if you do this type of declaration on my laptop right so one thing you need to take care you have to get ready with your laptop first of all if you are you want to learn c programming it's not like that just watch the lecture and that's it you've got the concept no you have to be get ready with your laptop with any id installed in my laptop i have vs code editor so i'll show you there if you don't have please install that thing or any other id in which you are comfortable right but you have to practice the concept on the same day if you are watching this lecture right now you got this concept arrays you have to practice after this lecture on your laptop if really you want to learn c programming right and that is the biggest mistake every beginner do yeah about simple concept it's silly thing no need to practice we will jump direct to the complex concept right the complicated concept that is the biggest mistake even the concept is very small very simple you have to practice that thing also right that is very important if you want to learn any programming language right so now before going to start this concept just want to tell you one thing if you are new in your programming field or you have just started your programming journey or if you are looking for dsa system design or full stack development courses then on an academy you can get access to these courses and free classes for all these topics right and here you can get free live classes every day where many topics are covered which are very important for interview preparation for software development roles in top companies and as a subscriber you will get access to all the courses and batches taken up by the best educators from the top product based companies and you will also get a dedicated doubt solving sessions plus a separate doubt support or discord here you will get a structured learning path with a course plan which is specifically designed to enhance your skills and to crack to help you crack interviews so the details of the relevant batches and the link of free classes you will get in the description box of this video use my code to access free classes as well as to get 10 discount on all the paid courses so if you are interested you can go for it so now back to the topic first of all we'll discuss why hearings need ophir is in any programming language here i'm discussing arrays in the context of c programming right i hope everybody is aware about the fundamental data types in float care right now see if i write something like this if you want to store a number if you want to process any number if you want to store in that memory in the computer memory what you need to do you have to declare a variable means you have to you know take a variable and there only we can store what any number you want to store right like in a this is what declaration of a variable of type integer right now here it means what compiler will do what some memory a location would be memory would be allocated to this a right a is you know what name of variable data type is integer now memory is what it's something like this so memory is what these are what bytes this is one byte one byte one byte so this is what memory it's type like a long tape of you can say these are bytes so now what in this memory what how many bytes would be allocated to this a size of integer remote it depends basically on machine to machine right somewhere it takes two bytes or somewhere in some compiler it takes four bytes whatever i am using it is it is taking about four bytes so we cannot say uh you know directly that integer will take two byte or increaser will take four bytes it can take two also four rows so it depends on your machine right here i am taking that is why invasive will take what four bytes so four bytes would be located to this a like suppose from any address address is what suppose this is 1000 addresses what in the form of hexadecimal form but for simplicity purpose i am taking just thousand so this is what thousand this is what 1000 1000 2003 something like this and suppose these four bytes has been allocated to this a one two three four four bytes for integer or you will take two bytes right now whatever number if you initialize if you want to store five like i'm initializing five so here this 5 would be stored first of all it would be converted into binary then it would be stored here right so now for simplicity purpose i am not taking these bytes i am converting it something like this just one box the name of this memory location is a here we have stored five and the address of this is what thousand these four bytes base addresses thousands so we will see we'll take one address is 1000 right now see if you want to store here another number 6 i want to store what you will do here 6 so this 5 would be overwritten means 5 is no more now and we have store six now we want to store seven so now six is no more we have stored seven it means what i hope you are getting my point you can store only one number right if you want to start another number the previous number has one but practically you you want to process you have to process large amount of data if suppose i want to in my class i have 60 students so now i want to store roll numbers of 60 students now how i can store one way is what i can declare what a b c like a into b and c and 60 variables you can declare and in one variable i can store role number one number two roll number three like this obviously this is silly thing no need i mean nobody wants this kind of thing if you do this kind of thing your program will be what filled with declaration and this initialization of variables only we don't want this kind of thing right so that is why what i want can we do something like this under one variable name only i can store 60 numbers yes that is possible with the help of arrays now that is called errors right under one variable name i can store more than one data item this is what suppose i am considering it as a number or a data item so here in array we can store more than one data item right but it is not the complete definition complete definition i will tell you step by step right so now if suppose i want to store roll number of 60 students of my class then and type obviously you have to tell the compiler the type based on that only you have the compiler will allocate you space the memory memory memory manager will allocate you space so suppose roll number obviously of integer type i am taking what name of here names i am taking a only and now you have to tell the size means how many number you want to store 60. right in these braces brackets size is 60. so this is what array now here data type a is what name of array if you want to take any name be any abc or anything you can take better to take a meaningful name suppose i want to store row number so better to take here what name what roll number so i am taking here what end roll number and size is 60. so name of my array is roll number size is 60 and data type is integer so this is what declaration of array this is how you declare an array right so now how many bytes would be allocated to this when this would be compiled then how many bytes would be allocated integer will take four bytes into how many number you want to store how many data items 60 so how many bytes should be located 240 bytes would be allocated here right and half these for 240 bytes would be located in consecutive memory locations continuous it's not like that here allocated four bytes then leaves ah leave some space then ten bytes then leave some space then in another place 20 bytes something like this no these 240 bytes would be located in consecutive uh memory locations like from thousand it is going to start suppose from thousand it is going to start till how many bytes thousand and 240 then how many bytes till one two four zero the address would be one two four zero till then continuous these memory locations would be allocated to this and now you can store here 16 hours right so now i hope need is clear to you why array what is needle fairy now what is array here just i am taking a simple array in a and size is only 5 i am taking right so now the declaration is also clear to you how to declare array general syntax if you write then what you will write here data type then what name of array and then in this bracket what size of array and semicolon this is what general syntax to declare array this is 1d array 2d ide is also there multi-dimensional array is also there 1d array means here we have only one row and multiple columns right now see the proper definition of array see here one one point you know it is what collection of more than one data item right but second point is what the condition here is what or you can see the constraint here is what all the data items should be of same type like suppose this is what integer the name of i mean the data type of the series what integer so all the five numbers must be of integer type right it's not like that you can store two integer type two character and one float no all should be of integer type like i can store here five number one two three four five or maybe 10 20 0 minus 1 0 these are it is a type this is correct this is correct but if you want to store here 10 20 and 1.2 and 0 and 2.2 this is not correct these are what integer but this is what float so this is room so the condition is what you can store more than one data item but all the data items should be of same type this is the condition right or you can say that homogeneous data collection of areas what collection of homogeneous data items and array can be of any type like here this is what i am taking integer integer type of array you can also take float or b and size is 10. here all the 10 data items should be your float type you can also take character array cap c 10 here all the data items the 10 data items you want to solve in this error should be of character type so now what you can say array is what collection of homogeneous data items which are stored in contiguous memory locations i will also discuss memory representation of array 1d array 2d array also multi-dimensional array in a separate video right when once we have complete all the concepts of arrays everything about errors then you can form a complete proper definition right but here in this for this video just uh you have to uh you know remember what collection of data items which are of same type or collection of homogeneous data items which are stored in contiguous memory locations right now i guess need is clear and waters array is clear now declaration of adding declaration is also clear clear this is the general sentence right but now see here you have to take care you have to take care some points something like this if i write here something like this i am not specifying the size but when you will write this line and here semicolon it will give error the compiler will give error you have to specify the size one thing you need to take here second thing what you need to take care about declaration here you can only specify what any constant like 5 10 15 anything constant but here you cannot write minus like minus 5 this would be incorrect so you can say what more specifically you can say this should be a positive number positive constant or if you say more specifically then what you can say this is also correct if you declare something like this in a 2 plus 2 is this correct yes this is correct 2 plus 2 is equivalent to 4 and 4 is what positive constant okay fine this is also fine a 3 into 2 3 into 2 is 6 6 is also constant this is also fine you can declare something like this and what you can declare you can also declare something like this in a and here you can write 10 by 2 [Music] this is also fine right that would be 5 right and if you write something like this 11 by 2 that is also 5. now so this is what you can say it's a expression also so one thing you need to take care the size of array should be a positive expression can be positive regular expression right this is what expression only because here we are writing operands and operator so this is what expression this is right this is right this is also right this is incorrect blank is also incorrect right and if you write something like this think suppose i am writing a and here another variable b is equal to 11 by 2 this would also give error right or you have to tell me you have to try this and you have to tell me is it correct or wrong you can also declare before this line int b because i am taking another variable b into b and in a is equal to in bracket you will say b is equal to any expression 11 by 2 so you have to tell me this will give error or this is correct and this is what 1d array because here we have only when you declare something like this i am taking this example then what 5 1 2 3 4 5 this name of this array is a right and here we can store five numbers so this is what four bytes this is what four bytes how many bytes total have been allocated to this array four into five that is 20 lines suppose was is started from thousand then the status would be what the next element address of next element would be one thousand and four four bytes for one integer then eight then dual then one thousand sixteen this is how in contiguous memory location 20 bytes would be allocated to this error and one more thing in this declaration see you cannot write something like this end a and size is n suppose you are taking in in n and you are writing here the variable no this should be what a constant so this is what incorrect right you have to try it at your own but you can use macros in that case you can write here what that whatever micro name you take how macros see i hope you are aware about macros before main function we declare what hash define macro name is i'm taking n and size i'm taking 5 here we will write what header files and then in main function what i am declaring array in a and here i can take size 1 the name of the macro is n this is correct that would be replaced with this five so this is what macro and it's better to when you use array it's better to use macros to define to this size of pairing why it is better to use macros that i'll show you in next video right so that that is correct but this is what not correct so everything the practical we will see in next video only i think that's it for this video in the next video i'll i'll tell you what uh initialization of arrays right and i'll show you this this macro is this character note and why it is better to use macros when we are you know dealing with arrays right on my laptop i'll show you in the next video but for this video that's it and you have to practice at your own you have to try all these declaration whether these are correct or not maybe i'm wrong whether these are you know giving error or not one more thing you have to try what int a and the size is zero is this correct or not this declare declaration correct or not right so you have to tell me comment works for this and this you have to try these for your own right i'll show you on my laptop in next video right so now i think that's it for this video i hope you are clear with the need of harry y array uh definition of eric not proper definition we have discussed because uh all the properties we are discussing one by one in all the videos but that whatever we have discussed in this video that you have i think you are clear with that thing and the declaration of arrays and different different types of declaration how you can declare array right so i'll see in the next video till then bye
Info
Channel: Jenny's lectures CS/IT NET&JRF
Views: 50,885
Rating: 4.9270387 out of 5
Keywords: data structure tutorials, operating system, data structure and algorithms, jayanti khatri lamba, jennys lectures, jenny data structures, jennys lectures DS, jenny lamba, jennys baby, jennys lectures baby, data structures
Id: 08LWytp6PNI
Channel Id: undefined
Length: 19min 29sec (1169 seconds)
Published: Thu Jul 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.